Skip to content

Commit

Permalink
0.2.2 hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
drdamour committed Sep 24, 2018
1 parent 43d379f commit fdb32ba
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 13 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.3.1 - TBD

## 0.2.2 - 2018-09-24
* Map values with keys or values containing , lead to index out of bound exceptions. now these props are unmodified (no links are generated)
* A future release will attempt to link these more complex things

## 0.2.1 - 2018-09-12
* Added navigation links between RQL result items and their related items

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.vitalize</groupId>
<artifactId>swole-dyn-admin</artifactId>
<version>0.3.1-SNAPSHOT</version>
<version>0.2.2</version>

<name>Swole Dyn Admin</name>
<description>A bunch of things to make your Oracle ATG Commerce Dyn Admin swole</description>
Expand Down
46 changes: 36 additions & 10 deletions src/main/java/com/vitalize/atg/dynadmin/SwoleGSAAdminServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ public void println(String s) throws IOException {

} else if (Set.class.equals(descriptorClass) || List.class.equals(descriptorClass)) {
//TODO: what happens if a value has a , ?
//one thing we could do is get the item and use the actual values
//instead of trying to parse the rql
String[] values = propValue.split(",");

for (int i = 0; i < values.length; i++) {
Expand All @@ -379,23 +381,47 @@ public void println(String s) throws IOException {
updatedValue = updatedValue.substring(1, updatedValue.length() - 1);

} else if (Map.class.equals(descriptorClass)){
//TODO: what happens if a value has a , ?
//parsing a map form RQL output is error prone
//in future maybe should actually retrieve the item
//and then generate result from that
//however that requires a lot more code

//Some examples of weird stuff
//key1=dog,cat,key2=other
//key,withcomma=car


String[] valuePairs = propValue.split(",");

//for now if it didn't break apart smooth...just skip it
boolean hasUglyStuff = false;



for (int i = 0; i < valuePairs.length; i++) {
String[] keyVal = valuePairs[i].split("=");

valuePairs[i] = keyVal[0] + "=" + linkToRQLQueryById(
pathToPropRepo,
propItemDescriptor.getItemDescriptorName(),
//TODO: what if name or value has =?
keyVal[1]
);
if(keyVal.length == 2) {
valuePairs[i] = keyVal[0] + "=" + linkToRQLQueryById(
pathToPropRepo,
propItemDescriptor.getItemDescriptorName(),
//TODO: what if name or value has =?
keyVal[1]
);
} else {
hasUglyStuff = true;
break;
}
}

updatedValue = Arrays.toString(valuePairs).replaceAll(">, ", ">,");
//remove brackets
updatedValue = updatedValue.substring(1, updatedValue.length() - 1);
if(hasUglyStuff){
updatedValue = propValue;
}else {

updatedValue = Arrays.toString(valuePairs).replaceAll(">, ", ">,");
//remove brackets
updatedValue = updatedValue.substring(1, updatedValue.length() - 1);
}
}

l = l.replace(
Expand Down
125 changes: 125 additions & 0 deletions src/test/java/com/vitalize/atg/dynadmin/SwoleGSAAdminServletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,135 @@ protected DynamoHttpServletRequest wrapRequest(HttpServletRequest req, HttpServl
)
);

}

@Test
public void testMapPropsOfRepoItemWithInterestingValuesAreLinked() throws ServletException, IOException, RepositoryException {


final StringBuilder allOutputBuilder = new StringBuilder();

doAnswer(
new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
allOutputBuilder.append(invocation.getArguments()[0]);
return null;
}
}
).when(mockOutputStream).println(anyString());


when(mockGSARepo.getItemDescriptorNames())
.thenReturn(new String[]{
"theItemType"
});

final String fakeGSARepoPath = "/some/path/to/Repo";

when(mockGSARepo.getAbsoluteName())
.thenReturn(fakeGSARepoPath);



RepositoryPropertyDescriptor fakePropMap = new FakeRepositoryPropertyDescriptor(
"propMap",
Map.class,
null,
RepositoryItem.class,
new FakeRepositoryItemDescriptor(
"propMapItemType",
mockGSARepo
)
);




RepositoryItemDescriptor fakeItemDescriptor = new FakeRepositoryItemDescriptor(
"theItemType",
mockGSARepo,
fakePropMap
);

when(mockGSARepo.getItemDescriptor("theItemType"))
.thenReturn(fakeItemDescriptor);


final String fakeDynAdminRepoPathToMockGSARepo = "/dyn/admin/path/";

SwoleGSAAdminServlet subject = new SwoleGSAAdminServlet(
mockGSARepo,
mockLogger,
mockNucleus,
mockTxManager
){
@Override
protected String formatServiceName(
String serviceName,
HttpServletRequest req
) {
if(fakeGSARepoPath == serviceName){
return fakeDynAdminRepoPathToMockGSARepo;
}

return "";
}

//This is a bit tricky to test because we are relying on the stubs impl for super class
//but that doesn't actually do anything...anyone have a better idea?
@Override
protected void printAdminInternal(HttpServletRequest req, HttpServletResponse res, ServletOutputStream out) throws ServletException, IOException {

out.println( PRECODE_MARKUP_ENTER);

//ATG seems to send all the multiline pre stuff in a single call to println
out.println(
" &lt;add-item item-descriptor=&quot;theItemType&quot; id=&quot;100217&quot;&gt; "

//map properties are weird, expecially if they contain , in values
+ "\n" + "&lt;set-property name=&quot;propMap&quot;>&lt;![CDATA[name=last, first,date=val2,dog,cat=foo,bar]]&gt;&lt;/set-property&gt;"

+ "\n" + " &lt;/add-item&gt; "


);

out.println(PRECODE_MARKUP_EXIT);

}

@Override
protected DynamoHttpServletRequest wrapRequest(HttpServletRequest req, HttpServletResponse res, String xml) {
return mockDynamoRequest;
}
};


subject.printAdmin(
mockRequest,
mockResponse,
mockOutputStream
);


String allOutput = allOutputBuilder.toString();


//map properties are weird
assertThat(
"",
allOutput,
containsString(

"&lt;set-property name=&quot;propMap&quot;>&lt;![CDATA[" +
"name=last, first" +
",date=val2" +
",dog,cat=foo,bar" +
"]]&gt;&lt;/set-property&gt;"

)
);


}

Expand Down

0 comments on commit fdb32ba

Please # to comment.