Skip to content

Commit

Permalink
Merge pull request #25 from vitiwari/master
Browse files Browse the repository at this point in the history
Default Template update
  • Loading branch information
vitiwari authored Jan 8, 2018
2 parents be9533c + 4de2dc2 commit f10a678
Show file tree
Hide file tree
Showing 19 changed files with 3,975 additions and 327 deletions.
Binary file added lib/api80_build002-8.0.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.bmc.truesight.saas</groupId>
<artifactId>remedy-tsi-integration-lib</artifactId>
<version>0.1.5_01</version>
<version>0.1.7</version>
<name>remedy-tsi-integration-lib</name>
<description>Library for integration of Remedy Incidents and Change tickets into Truesight Intelligence as Events</description>

Expand Down Expand Up @@ -49,6 +49,8 @@
<groupId>com.bmc.arsys.api</groupId>
<artifactId>api80_build002</artifactId>
<version>${arsys.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/api80_build002-8.0.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,23 @@ RemedyEventResponse readRemedyTickets(ARServerUser arServerContext, ARServerForm
*
* @param user {@link ARServerUser} instance.
* @param form ARServerForm instance
* @throws RemedyReadFailedException
* @throws RemedyReadFailedException throws exception
* @return Map Returns FieldId field Map
*/
Map<Integer, Field> getFieldsMap(ARServerUser user, ARServerForm form) throws RemedyReadFailedException;

/**
* This method gets List of valid/invalid Events for the list of entry Ids
*
* @param arServerContext ARServerUser instance
* @param formName Incident or change formName
* @param template template object
* @param ids list of Entry ids
* @param adapter RemedyEntryEventAdapter
* @return RemedyEventResponse Returns the result
* @throws RemedyReadFailedException exception
*/
RemedyEventResponse readRemedyTicketsWithId(ARServerUser arServerContext, ARServerForm formName, Template template,
List<String> ids, RemedyEntryEventAdapter adapter) throws RemedyReadFailedException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface TemplateParser {
* This method reads and parse from a JSON file. This function is used in
* case template JSON is available in json file
*
* @param defaultTemplate Instance of DefaultTemplate
* @param fileName Template JSON fileName
* @return {@link Template}
* @throws ParsingException Throws this exception if JSON parsing is not
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.bmc.truesight.saas.remedy.integration.adapter;

import java.lang.reflect.Field;
import java.util.Currency;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bmc.arsys.api.AttachmentField;
import com.bmc.arsys.api.CurrencyField;
import com.bmc.arsys.api.DateTimeField;
import com.bmc.arsys.api.DecimalField;
import com.bmc.arsys.api.Entry;
import com.bmc.arsys.api.EnumItem;
import com.bmc.arsys.api.IntegerField;
import com.bmc.arsys.api.SelectionField;
import com.bmc.arsys.api.SelectionFieldLimit;
import com.bmc.arsys.api.TimeOnlyField;
Expand All @@ -20,6 +24,7 @@
import com.bmc.truesight.saas.remedy.integration.beans.FieldItem;
import com.bmc.truesight.saas.remedy.integration.beans.TSIEvent;
import com.bmc.truesight.saas.remedy.integration.beans.Template;
import com.bmc.truesight.saas.remedy.integration.util.Constants;

/**
* This is an adapter which converts the remedy {@link Entry} items into
Expand Down Expand Up @@ -65,24 +70,24 @@ public TSIEvent convertEntryToEvent(Template template, Entry entry) {
source.setType(getValueFromEntry(template, entry, source.getType()));
source.setRef(getValueFromEntry(template, entry, source.getRef()));

EventSource sender = event.getSender();
/*EventSource sender = event.getSender();
sender.setName(getValueFromEntry(template, entry, sender.getName()));
sender.setType(getValueFromEntry(template, entry, sender.getType()));
sender.setRef(getValueFromEntry(template, entry, sender.getRef()));
sender.setRef(getValueFromEntry(template, entry, sender.getRef()));*/
return event;

}

private String getValueFromEntry(Template template, Entry entry, String placeholder) {
if (placeholder.startsWith("@")) {
FieldItem fieldItem = template.getFieldItemMap().get(placeholder);
FieldItem fieldItem = template.getFieldDefinitionMap().get(placeholder);
com.bmc.arsys.api.Field field = fieldIdFieldMap.get(fieldItem.getFieldId());

if (field != null) {
Value value = entry.get(fieldItem.getFieldId());
if (field instanceof SelectionField) {
SelectionFieldLimit sFieldLimit = (SelectionFieldLimit) field.getFieldLimit();
String returnVal = "";
String returnVal = Constants.NONE_VALUE;
if (value.getValue() != null) {
if (sFieldLimit != null) {
List<EnumItem> eItemList = sFieldLimit.getValues();
Expand All @@ -99,20 +104,27 @@ private String getValueFromEntry(Template template, Entry entry, String placehol
return returnVal;
}
} else {
return "";
return Constants.NONE_VALUE;
}
} else if (field instanceof DateTimeField || field instanceof TimeOnlyField) {
Timestamp dateTimeTS = (Timestamp) value.getValue();
if (dateTimeTS != null) {
return Long.toString(dateTimeTS.getValue());
} else {
return "";
return Constants.NONE_VALUE;
}
} else if (field instanceof AttachmentField) {
log.debug("FieldId,FieldName ({},{}) is an attachment field which is not expected in the mapping, ignoring the attachment field.", field.getFieldID(), field.getName());
return "";
} else {
return Constants.NONE_VALUE;
} else if (field instanceof IntegerField || field instanceof CurrencyField || field instanceof DecimalField) {
String val = "";
if (value != null && value.getValue() != null) {
val = value.getValue().toString();
}
return val;

} else {
String val = Constants.NONE_VALUE;
if (value != null && value.getValue() != null) {
val = value.getValue().toString();
if (fieldItem.getValueMap() != null && fieldItem.getValueMap().get(val) != null) {
Expand All @@ -122,14 +134,13 @@ private String getValueFromEntry(Template template, Entry entry, String placehol
}
}
return val;

}
} else {
return "";
return Constants.NONE_VALUE;
}
} else if (placeholder.startsWith("#")) {
Field fieldItem;
String val = "";
String val = Constants.NONE_VALUE;
try {
fieldItem = template.getConfig().getClass().getDeclaredField(placeholder.substring(1));
if (fieldItem != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bmc.truesight.saas.remedy.integration.beans;

public enum FieldInstance {

CharacterField("CharacterField"), IntegerField("IntegerField"), DecimalField("DecimalField"), RealField(
"RealField"), DiaryField("DiaryField"), SelectionField("SelectionField"), AttachmentField(
"AttachmentField"), CurrencyField("CurrencyField"), DateOnlyField("DateOnlyField"), TimeOnlyField(
"TimeOnlyField"), DateTimeField("DateTimeField"), UnknownField("UnknownField");

private final String text;

private FieldInstance(String text) {
this.text = text;
}

@Override
public String toString() {
return text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,49 @@

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
* This is a pojo class, which is used in the
* {@link com.bmc.truesight.saas.remedy.integration.beans.Template Template}
*
* @author vitiwari
*
*/
@JsonInclude(Include.NON_NULL)
public class FieldItem {

private Integer fieldId;
private String fieldName;
private String fieldType;
private String fieldInstance;
Map<String, String> valueMap;

public String getFieldName() {
return fieldName;
}

public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}

public String getFieldType() {
return fieldType;
}

public void setFieldType(String fieldType) {
this.fieldType = fieldType;
}

public String getFieldInstance() {
return fieldInstance;
}

public void setFieldInstance(String fieldInstance) {
this.fieldInstance = fieldInstance;
}

public Map<String, String> getValueMap() {
return valueMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.bmc.truesight.saas.remedy.integration.beans;

public class InvalidEvent {

private String entryId;
private TSIEvent invalidEvent;
private long eventSize;
private String maxSizePropertyName;
private long propertySize;

public InvalidEvent(String entryId) {
this.entryId = entryId;
}

public TSIEvent getInvalidEvent() {
return invalidEvent;
}

public void setInvalidEvent(TSIEvent invalidEvent) {
this.invalidEvent = invalidEvent;
}

public long getEventSize() {
return eventSize;
}

public void setEventSize(long eventSize) {
this.eventSize = eventSize;
}

public String getMaxSizePropertyName() {
return maxSizePropertyName;
}

public void setMaxSizePropertyName(String maxSizePropertyName) {
this.maxSizePropertyName = maxSizePropertyName;
}

public long getPropertySize() {
return propertySize;
}

public void setPropertySize(long propertySize) {
this.propertySize = propertySize;
}

public String getEntryId() {
return entryId;
}

public void setEntryId(String entryId) {
this.entryId = entryId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
public class RemedyEventResponse {

private List<TSIEvent> validEventList;
private List<TSIEvent> invalidEventList;
private int largeInvalidEventCount;
private List<InvalidEvent> invalidEventList;

public List<TSIEvent> getValidEventList() {
return validEventList;
}

public void setValidEventList(List<TSIEvent> validEventList) {
this.validEventList = validEventList;
public List<InvalidEvent> getInvalidEventList() {
return invalidEventList;
}

public int getLargeInvalidEventCount() {
return largeInvalidEventCount;
public void setInvalidEventList(List<InvalidEvent> invalidEventList) {
this.invalidEventList = invalidEventList;
}

public void setLargeInvalidEventCount(int largeInvalidEventCount) {
this.largeInvalidEventCount = largeInvalidEventCount;
public List<TSIEvent> getValidEventList() {
return validEventList;
}

public List<TSIEvent> getInvalidEventList() {
return invalidEventList;
public void setValidEventList(List<TSIEvent> validEventList) {
this.validEventList = validEventList;
}

public void setInvalidEventList(List<TSIEvent> invalidEventList) {
this.invalidEventList = invalidEventList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class TSIEvent {
private String createdAt;
private String eventClass;
private EventSource source;
private EventSource sender;
//private EventSource sender;

public TSIEvent(TSIEvent payload) {
this.setTitle(payload.getTitle());
this.setFingerprintFields(new ArrayList<String>(payload.fingerprintFields));
this.setEventClass(payload.getEventClass());
this.setCreatedAt(payload.getCreatedAt());
this.setProperties(new HashMap<String, String>(payload.getProperties()));
this.setSender(new EventSource(payload.getSender()));
//this.setSender(new EventSource(payload.getSender()));
this.setSource(new EventSource(payload.getSource()));
this.setSeverity(payload.getSeverity());
this.setStatus(payload.getStatus());
Expand Down Expand Up @@ -82,14 +82,13 @@ public void setSource(EventSource source) {
this.source = source;
}

public EventSource getSender() {
/*public EventSource getSender() {
return sender;
}
public void setSender(EventSource sender) {
this.sender = sender;
}

}*/
public Map<String, String> getProperties() {
return properties;
}
Expand Down Expand Up @@ -135,8 +134,8 @@ public String toString() {
builder.append(eventClass);
builder.append(", \"source\":");
builder.append(source);
builder.append(", \"sender\":");
builder.append(sender);
//builder.append(", \"sender\":");
// builder.append(sender);
builder.append("}");
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Template {

private Configuration config;
private TSIEvent eventDefinition;
private Map<String, FieldItem> FieldItemMap;
private Map<String, FieldItem> fieldDefinitionMap;

public Configuration getConfig() {
return config;
Expand All @@ -31,11 +31,12 @@ public void setEventDefinition(TSIEvent eventDefinition) {
this.eventDefinition = eventDefinition;
}

public Map<String, FieldItem> getFieldItemMap() {
return FieldItemMap;
public Map<String, FieldItem> getFieldDefinitionMap() {
return fieldDefinitionMap;
}

public void setFieldItemMap(Map<String, FieldItem> fieldItemMap) {
FieldItemMap = fieldItemMap;
public void setFieldDefinitionMap(Map<String, FieldItem> fieldDefinitionMap) {
this.fieldDefinitionMap = fieldDefinitionMap;
}

}
Loading

0 comments on commit f10a678

Please sign in to comment.