Skip to content

Commit

Permalink
fix(status holding): Handle messages with status holding.
Browse files Browse the repository at this point in the history
When a message is read from PI with status holding the end time is null.
Added handling for the holding status and allow null end times. null end times are sorted last in the message display.

Started changes to ApplicationProperties.java to allow configuration for the maximum number of messages per WS call as well as the message initial start date on first run of the application. ApplicationProperties.java is updated - now need to refactor zpi_ejb to use the values instead of constants.
  • Loading branch information
js1972 committed Feb 3, 2014
1 parent edaa24c commit 6ca5e87
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PI host name to read messages from
## PI host name to read messages from - must include protocol (http/https)
#? onlinemodifiable = true
#% type = STRING
HOST_URL = app1pod
Expand All @@ -11,4 +11,15 @@ USERNAME = dummy_user
## The password of the user
#? secure = true; onlinemodifiable = true
#% type = STRING;
PASSWORD = abcdefg
PASSWORD = abcdefg

## Start date for first run of pimon. Messages are collected from this date. Only read is message cache is empty.
## Format: dd/mm/yyyy
#? onlinemodifiable = true
#% type = STRING
START_DATE = 01/01/2014

## Maximum number of messages to read from PI on each update
#? onlinemodifiable = true
#% type = STRING
MAX_RESULTS = 5000
3 changes: 3 additions & 0 deletions jaylin.com.au/zpi_ejb/_comp/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<classpath>
<classpathentry kind="src" path=".apt_generated"/>
<classpathentry kind="src" path="ejbModule"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="com.sap.ide.dii.jdt.requiredDcs"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="mockito-all-1.9.5.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#Thu Oct 17 17:07:36 WST 2013
#Thu Jan 30 13:59:00 WST 2014
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.processAnnotations=enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<wb-module deploy-name="LocalDevelopment~zpi_ejb~jaylin.com.au">
<wb-resource deploy-path="/" source-path="/ejbModule"/>
<wb-resource deploy-path="/" source-path="/.apt_generated"/>
<wb-resource deploy-path="/" source-path="/test"/>
<property name="java-output-path" value="/LocalDevelopment~zpi_ejb~jaylin.com.au/bin"/>
</wb-module>
</project-modules>
76 changes: 76 additions & 0 deletions jaylin.com.au/zpi_ejb/_comp/def/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,35 @@
<entity>
<name>ApplicationProperties</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>ApplicationProperties</caption>
<description>ApplicationProperties</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>ApplicationProperties</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>ApplicationProperties</caption>
<description>ApplicationProperties</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>ApplicationPropertiesLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>ApplicationPropertiesLocal</caption>
<description>ApplicationPropertiesLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>ApplicationPropertiesLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>ApplicationPropertiesLocal</caption>
<description>ApplicationPropertiesLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>AuditLogEntryData</name>
<package>data/api/mdt/aii/sap/com</package>
Expand Down Expand Up @@ -99,15 +119,35 @@
<entity>
<name>PIMessageHandler</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>PIMessageHandler</caption>
<description>PIMessageHandler</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>PIMessageHandler</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>PIMessageHandler</caption>
<description>PIMessageHandler</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>PIMessageHandlerLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>PIMessageHandlerLocal</caption>
<description>PIMessageHandlerLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>PIMessageHandlerLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>PIMessageHandlerLocal</caption>
<description>PIMessageHandlerLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>PITimeStamp</name>
<package>au/com/jaylin/persistence/ejbs/helpers</package>
Expand Down Expand Up @@ -140,17 +180,53 @@
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>TimestampException</name>
<package>au/com/jaylin/persistence/ejbs/helpers</package>
<caption>TimestampException</caption>
<description>TimestampException</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>TimestampException</name>
<package>au/com/jaylin/persistence/ejbs/helpers</package>
<caption>TimestampException</caption>
<description>TimestampException</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>WebServiceEndPoint</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>WebServiceEndPoint</caption>
<description>WebServiceEndPoint</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>WebServiceEndPoint</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>WebServiceEndPoint</caption>
<description>WebServiceEndPoint</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
<entity>
<name>WebServiceEndPointLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>WebServiceEndPointLocal</caption>
<description>WebServiceEndPointLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Class</entity-sub-type>
</entity>
<entity>
<name>WebServiceEndPointLocal</name>
<package>au/com/jaylin/persistence/ejbs</package>
<caption>WebServiceEndPointLocal</caption>
<description>WebServiceEndPointLocal</description>
<entity-type>Java Class</entity-type>
<entity-sub-type>Source</entity-sub-type>
</entity>
</entities>
</public-part>
1 change: 0 additions & 1 deletion jaylin.com.au/zpi_ejb/_comp/ejbModule/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Manifest-Version: 1.0
Class-Path:

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package au.com.jaylin.persistence.ejbs;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;

import javax.ejb.Stateless;
Expand All @@ -25,11 +29,15 @@ public class ApplicationProperties implements ApplicationPropertiesLocal {
private static final String HOST_URL = "HOST_URL";
private static final String USERNAME = "USERNAME";
private static final String PASSWORD = "PASSWORD";
private static final String START_DATE = "START_DATE";
private static final String MAX_RESULTS = "MAX_RESULTS";

private Location logger = Location.getLocation("pimon.application.properties");
private String hostUrl;
private String username;
private String password;
private String startDate;
private String maxResults;

public ApplicationProperties() {
logger.infoT("Creating the logger");
Expand All @@ -43,22 +51,66 @@ public ApplicationProperties() {
hostUrl = appProps.getProperty(HOST_URL);
username = appProps.getProperty(USERNAME);
password = appProps.getProperty(PASSWORD);
startDate = appProps.getProperty(START_DATE);
maxResults = appProps.getProperty(MAX_RESULTS);
}
catch (Exception e) {
logger.errorT("EXCEPTION: " + e.getMessage());
throw new RuntimeException("UNABLE TO READ APPLICATION PROPERTIES : " + e.getMessage());
throw new RuntimeException("UNABLE TO READ APPLICATION PROPERTIES: " + e.getMessage());
}

// // check entered url - remove trailing slash if it exists and check for protocol
// if (hostUrl.endsWith("/")) {
// hostUrl = hostUrl.substring(0, hostUrl.length() - 1);
// }
// if (!hostUrl.matches("^(http|https)://")) {
// logger.errorT("ApplicationProperties exception: Invalid host url provided. Missing protocol (http|https)");
// throw new RuntimeException("ApplicationProperties: Invalid host url provided. Missing protocol (http|https)");
// }
//
// // check entered start date follows dd/mm/yyyy or dd-mm-yyyy pattern (note: backslashes are escaped by another backslash)
// if (!startDate.matches("/(\\d+)(-|\\/)(\\d+)(?:-|\\/)(?:(\\d+)\\s+(\\d+):(\\d+)(?::(\\d+))?(?:\\.(\\d+))?)?/")) {
// logger.errorT("ApplicationProperties exception: Invalid start_date provided. Format must be dd/mm/yyyy or dd-mm-yyyy: " + startDate);
// throw new RuntimeException("ApplicationProperties exception: Invalid start_date provided. Format must be dd/mm/yyyy or dd-mm-yyyy: " + startDate);
// }
//
// if (Integer.parseInt(maxResults) == 0) {
// logger.errorT("ApplicationProperties exception: max_results cannot be 0");
// throw new RuntimeException("ApplicationProperties exception: max_results cannot be 0");
// }
}

public String getHostUrl() {
return hostUrl;
}

public String getUsername() {
if (username.equals("")) {
throw new RuntimeException("ApplicationProperties exception: Enter a username");
}
return username;
}

public String getPassword() {
if (password.equals("")) {
throw new RuntimeException("ApplicationProperties exception: Enter a password");
}
return password;
}

public Date getStartDate() {
Date d = null;

try {
d = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(startDate);
} catch (ParseException e) {
throw new RuntimeException("ApplicationProperties exception: Unable to parse start_date: " + startDate);
};

return d;
}

public int getMaxResults() {
return Integer.parseInt(maxResults);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MessageDetails {
@Stateless
public class PIMessageHandler implements PIMessageHandlerLocal {
private static final int GET_LOG_ENTRIES_MAX_RESULTS = 1000;
private static final int GET_MESSAGES_MAX_RESULTS = 1000;
private static final int GET_MESSAGES_MAX_RESULTS = 5000;

@EJB
private PIMessageFacadeLocal piMessageFacade;
Expand Down Expand Up @@ -281,8 +281,7 @@ private MessageDetails callMessageDetailsWS(String msgKey, String msgId) {
byteArray = ws.call().getMessageBytesJavaLangStringBoolean(msgKey, false);
}
catch (Exception e) {
//what goes here?!?
throw new RuntimeException("*** SHIT *** FAILED TO GET PAYLOAD FOR MSGKEY: " + msgKey);
throw new RuntimeException("Read message payload web service failed: ws.call().getMessageBytesJavaLangStringBoolean(msgKey, false). MsgId: " + msgId + ", MsgKey: " + msgKey);
}

logger.infoT("PIMessageHandler.callMessageDetailsWS(): getMessageBytesJavaLangStringBoolean() WS SUCCESS");
Expand Down Expand Up @@ -459,7 +458,14 @@ private void readPayloadsAndBuildMessageEntities(List<AdapterFrameworkData> msgs
msgData.setSender_namespace(assignStringValue(m.getSenderInterface().getValue().getNamespace().getValue()));
msgData.setSender_party(assignStringValue(m.getSenderParty().getValue().getName().getValue()));
msgData.setStart_time(m.getStartTime().getValue().toGregorianCalendar().getTime());
msgData.setEnd_time(m.getEndTime().getValue().toGregorianCalendar().getTime());

// End time cane be null when message has "holding" status!
if (m.getEndTime() == null) {
msgData.setEnd_time(null);
} else {
msgData.setEnd_time(m.getEndTime().getValue().toGregorianCalendar().getTime());
}

msgData.setStatus(assignStringValue(m.getStatus().getValue()));

messageDetails = callMessageDetailsWS(m.getMessageKey().getValue(), m.getMessageID().getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package au.com.jaylin.persistence.ejbs;

import java.util.Properties;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.sap.engine.services.configuration.appconfiguration.ApplicationPropertiesAccess;
import com.sap.engine.services.configuration.appconfiguration.ApplicationPropertiesChangeListener;


@RunWith(MockitoJUnitRunner.class)
public class ApplicationProperties_Test {

@Mock
InitialContext ctx;

@InjectMocks
ApplicationProperties appProperties;

@Test
public void testCreateApplicationProperties() throws NamingException {
when((ApplicationPropertiesAccess)ctx.lookup("ApplicationConfiguration")).thenReturn(new ApplicationPropertiesAccess() {

@Override
public void removeApplicationPropertiesChangedListener(
ApplicationPropertiesChangeListener arg0) {
// TODO Auto-generated method stub

}

@Override
public Properties getSystemProfile() {
// TODO Auto-generated method stub
return null;
}

@Override
public Properties getApplicationProperties() {
// build up test double for java properties object
Properties p = new Properties();
p.setProperty("HOST_URL", "http://abc.company.com:50001");
return p;
}

@Override
public void addApplicationPropertiesChangedListener(
ApplicationPropertiesChangeListener arg0) {
// TODO Auto-generated method stub

}
});

// String url = appProperties.getHostUrl();
}
}
Loading

0 comments on commit 6ca5e87

Please sign in to comment.