From 8c8072d803242e7df3b54ce9e1a7e20212cc683a Mon Sep 17 00:00:00 2001 From: Laramie Crocker Date: Fri, 27 May 2011 22:19:48 +0000 Subject: [PATCH] CSPACE-573 Added *order* field to schema for Vocabularies and list result. Developed and installed dditional tests validating work on hierarchies, issues: CSPACE-4037 CSPACE-4040 CSPACE-4042 CSPACE-4037 CSPACE-4045 --- .../IntegrationTests/xmlreplay/XmlReplay.java | 35 ++- .../xmlreplay/XmlReplayReport.java | 32 ++- .../xmlreplay/XmlReplayTest.java | 8 +- .../reports-include.css | 0 .../reports-include.js | 0 .../xmlreplay/location/hierarchy/0-note.xml | 9 + .../hierarchy/3-locations_w_relations.xml | 4 - .../4-locations_w_relations_mixed.xml | 37 +++ .../location-hierarchy-dual-parents.xml | 219 ++++++++++++++++++ .../location/location-mixed-hierarchy.xml | 88 +++++++ .../vocabulary/AuthorityItemJAXBSchema.java | 1 + .../common/vocabulary/AuthorityResource.java | 94 ++++---- .../services/common/vocabulary/Hierarchy.java | 192 +++++++++++++++ .../services/common/XmlTools.java | 9 +- .../java/RemoteDocumentModelHandlerImpl.java | 6 +- .../schemas/vocabularyitems_common.xsd | 2 +- .../main/resources/vocabularyitem_common.xsd | 75 +++--- .../VocabularyItemDocumentModelHandler.java | 8 +- 18 files changed, 709 insertions(+), 110 deletions(-) rename services/IntegrationTests/src/test/resources/test-data/xmlreplay/{TEST-REPORTS => _includes}/reports-include.css (100%) rename services/IntegrationTests/src/test/resources/test-data/xmlreplay/{TEST-REPORTS => _includes}/reports-include.js (100%) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/0-note.xml create mode 100755 services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/4-locations_w_relations_mixed.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy-dual-parents.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-mixed-hierarchy.xml create mode 100644 services/authority/src/main/java/org/collectionspace/services/common/vocabulary/Hierarchy.java diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java index 5b80c7595..ebf19c30e 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java @@ -20,16 +20,21 @@ import java.util.*; */ public class XmlReplay { - public XmlReplay(String basedir){ + public XmlReplay(String basedir, String reportsDir){ this.basedir = basedir; this.serviceResultsMap = createResultsMap(); this.reportsList = new ArrayList(); + this.reportsDir = reportsDir; } public static final String DEFAULT_CONTROL = "xml-replay-control.xml"; public static final String DEFAULT_MASTER_CONTROL = "xml-replay-master.xml"; public static final String DEFAULT_DEV_MASTER_CONTROL = "dev-master.xml"; + private String reportsDir = ""; + public String getReportsDir(){ + return reportsDir; + } private String basedir = "."; //set from constructor. public String getBaseDir(){ return basedir; @@ -89,7 +94,7 @@ public class XmlReplay { } public String toString(){ - return "XmlReplay{"+this.basedir+", "+this.defaultAuthsMap+", "+this.dump+'}'; + return "XmlReplay{"+this.basedir+", "+this.defaultAuthsMap+", "+this.dump+", "+this.reportsDir+'}'; } // ============== METHODS =========================================================== @@ -166,7 +171,7 @@ public class XmlReplay { test = runNode.valueOf("@test"); //may be empty //Create a new instance and clone only config values, not any results maps. - XmlReplay replay = new XmlReplay(basedir); + XmlReplay replay = new XmlReplay(basedir, this.reportsDir); replay.setControlFileName(controlFile); replay.setProtoHostPort(protoHostPort); replay.setAutoDeletePOSTS(isAutoDeletePOSTS()); @@ -178,7 +183,7 @@ public class XmlReplay { list.add(results); this.reportsList.addAll(replay.getReportsList()); //Add all the reports from the inner replay, to our master replay's reportsList, to generate the index.html file. } - XmlReplayReport.saveIndexForMaster(basedir, masterFilename, this.reportsList); + XmlReplayReport.saveIndexForMaster(basedir, reportsDir, masterFilename, this.reportsList); return list; } @@ -193,7 +198,8 @@ public class XmlReplay { dump, this.protoHostPort, this.defaultAuthsMap, - this.reportsList); + this.reportsList, + this.reportsDir); return result; } @@ -208,7 +214,8 @@ public class XmlReplay { dump, this.protoHostPort, this.defaultAuthsMap, - this.reportsList); + this.reportsList, + this.reportsDir); if (result.size()>1){ throw new IndexOutOfBoundsException("Multiple ("+result.size()+") tests with ID='"+testID+"' were found within test group '"+testGroupID+"', but there should only be one test per ID attribute."); } @@ -457,14 +464,15 @@ public class XmlReplay { Dump dump, String protoHostPortParam, AuthsMap defaultAuths, - List reportsList) + List reportsList, + String reportsDir) throws Exception { //Internally, we maintain two collections of ServiceResult: // the first is the return value of this method. // the second is the serviceResultsMap, which is used for keeping track of CSIDs created by POSTs, for later reference by DELETE, etc. List results = new ArrayList(); - XmlReplayReport report = new XmlReplayReport(); + XmlReplayReport report = new XmlReplayReport(reportsDir); String controlFile = Tools.glue(xmlReplayBaseDir, "/", controlFileName); org.dom4j.Document document; @@ -719,7 +727,7 @@ public class XmlReplay { String localName = m.getName();//don't instantiate, just use File to extract file name without directory. String reportName = localName+'-'+testGroupID+".html"; - File resultFile = report.saveReport(xmlReplayBaseDir, reportName); + File resultFile = report.saveReport(xmlReplayBaseDir, reportsDir, reportName); if (resultFile!=null) { String toc = report.getTOC(reportName); reportsList.add(toc); @@ -778,6 +786,7 @@ public class XmlReplay { CommandLine line = parser.parse(options, args); String xmlReplayBaseDir = opt(line, "xmlReplayBaseDir"); + String reportsDir = opt(line, "reportsDir"); String testGroupID = opt(line, "testGroupID"); String testID = opt(line, "testID"); String autoDeletePOSTS = opt(line, "autoDeletePOSTS"); @@ -785,6 +794,10 @@ public class XmlReplay { String controlFilename = opt(line, "controlFilename"); String xmlReplayMaster = opt(line, "xmlReplayMaster"); + if (Tools.isBlank(reportsDir)){ + reportsDir = xmlReplayBaseDir + XmlReplayTest.REPORTS_DIRNAME; + } + reportsDir = Tools.fixFilename(reportsDir); xmlReplayBaseDir = Tools.fixFilename(xmlReplayBaseDir); controlFilename = Tools.fixFilename(controlFilename); @@ -829,7 +842,7 @@ public class XmlReplay { if (Tools.notEmpty(controlFilename)){ System.out.println("WARN: controlFilename: "+controlFilename+" will not be used because master was specified. Running master: "+xmlReplayMaster); } - XmlReplay replay = new XmlReplay(xmlReplayBaseDirResolved); + XmlReplay replay = new XmlReplay(xmlReplayBaseDirResolved, reportsDir); replay.readOptionsFromMasterConfigFile(xmlReplayMaster); replay.setAutoDeletePOSTS(bAutoDeletePOSTS); Dump dumpFromMaster = replay.getDump(); @@ -840,7 +853,7 @@ public class XmlReplay { Dump dump = getDumpConfig(); dump.payloads = Tools.isTrue(dumpResults); List reportsList = new ArrayList(); - runXmlReplayFile(xmlReplayBaseDirResolved, controlFilename, testGroupID, testID, createResultsMap(), bAutoDeletePOSTS, dump, "", null, reportsList); + runXmlReplayFile(xmlReplayBaseDirResolved, controlFilename, testGroupID, testID, createResultsMap(), bAutoDeletePOSTS, dump, "", null, reportsList, reportsDir); System.out.println("DEPRECATED: reportsList is generated, but not dumped: "+reportsList.toString()); } } catch (ParseException exp) { diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java index d46c07926..144856196 100644 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java @@ -15,6 +15,8 @@ import java.util.List; * @author laramie */ public class XmlReplayReport { + public static final String INCLUDES_DIR = "_includes"; + protected static final String HTML_PAGE_END = ""; protected static final String TOPLINKS = "Show All Payloads" + "Hide All Payloads"; @@ -40,6 +42,14 @@ public class XmlReplayReport { private static final String SP = "   "; + public XmlReplayReport(String reportsDir){ + this.reportsDir = reportsDir; + } + + private String reportsDir = ""; + public String getReportsDir(){ + return reportsDir; + } protected static String formatCollapse(String myDivID, String linkText){ return ""+linkText+"" @@ -115,8 +125,8 @@ public class XmlReplayReport { private List tocList = new ArrayList(); public static String formatPageStart(String xmlReplayBaseDir){ - String script = FileTools.readFile(xmlReplayBaseDir, "TEST-REPORTS/reports-include.js"); - String style = FileTools.readFile(xmlReplayBaseDir, "TEST-REPORTS/reports-include.css"); + String script = FileTools.readFile(xmlReplayBaseDir, INCLUDES_DIR+"/reports-include.js"); + String style = FileTools.readFile(xmlReplayBaseDir, INCLUDES_DIR+"/reports-include.css"); return "\r\n"; } - public File saveReport(String xmlReplayBaseDir, String reportName) { + public File saveReport(String xmlReplayBaseDir, String reportsDir, String reportName) { try { - File resultFile = FileTools.saveFile(getReportsDir(xmlReplayBaseDir), reportName, this.getPage(xmlReplayBaseDir), true); + File resultFile = FileTools.saveFile(reportsDir, reportName, this.getPage(xmlReplayBaseDir), true); if (resultFile!=null) { String resultFileName = resultFile.getCanonicalPath(); //System.out.println("XmlReplay summary reports saved to directory: "+resultFile.getParent()); @@ -134,21 +144,21 @@ public class XmlReplayReport { return resultFile; } } catch (Exception e){ - System.out.println("ERROR saving XmlReplay report in basedir: "+xmlReplayBaseDir+" reportName: "+reportName+" error: "+e); + System.out.println("ERROR saving XmlReplay report in basedir: "+reportsDir+" reportName: "+reportName+" error: "+e); } return null; } - public static String getReportsDir(String basename){ - return Tools.glue(basename,"/","TEST-REPORTS"); - } + //public static String getReportsDir(String basename){ + // return Tools.glue(basename,"/","TEST-REPORTS"); + //} /** @param localMasterFilename should be a local filename for the index of each xmlReplay master control file, e.g. objectexit.xml * so what gets written to disk will be something like index.objectexit.xml.html . The actual filename will be available from * the returned File object if successful. * @return File if successful, else returns null. */ - public static File saveIndexForMaster(String xmlReplayBaseDir, String localMasterFilename, List reportsList){ + public static File saveIndexForMaster(String xmlReplayBaseDir, String reportsDir, String localMasterFilename, List reportsList){ String masterFilename = "index."+localMasterFilename+".html"; try{ StringBuffer sb = new StringBuffer(formatPageStart(xmlReplayBaseDir)); @@ -160,9 +170,9 @@ public class XmlReplayReport { } sb.append(HTML_PAGE_END); - return FileTools.saveFile(getReportsDir(xmlReplayBaseDir),masterFilename, sb.toString(), false); + return FileTools.saveFile(reportsDir,masterFilename, sb.toString(), false); } catch (Exception e){ - System.out.println("ERROR saving XmlReplay report index: in xmlReplayBaseDir: "+xmlReplayBaseDir+"localMasterFilename: "+localMasterFilename+" masterFilename: "+masterFilename+" list: "+reportsList+" error: "+e); + System.out.println("ERROR saving XmlReplay report index: in xmlReplayBaseDir: "+reportsDir+"localMasterFilename: "+localMasterFilename+" masterFilename: "+masterFilename+" list: "+reportsList+" error: "+e); return null; } } diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java index 641e2cbd7..27d0fce30 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTest.java @@ -38,6 +38,8 @@ import java.util.List; public class XmlReplayTest { public static final String XMLREPLAY_REL_DIR_TO_MODULE = "/src/test/resources/test-data/xmlreplay"; + public static final String REPORTS_DIRNAME = "xml-replay-reports"; + public static final String XMLREPLAY_REL_DIR_REPORTS_TO_MODULE= "/target/"+REPORTS_DIRNAME; /** To use this method, you should have a test repository of xml files in the path * defined by XMLREPLAY_REL_DIR_TO_MODULE, relative to your pom.xml file, but normally @@ -47,7 +49,8 @@ public class XmlReplayTest { public static XmlReplay createXmlReplayForModule() throws Exception { String pwd = (new File(".")).getCanonicalPath(); System.out.println("createXmlReplayForModule.pwd: "+pwd); - XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE); + XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE, + pwd+XMLREPLAY_REL_DIR_REPORTS_TO_MODULE); System.out.println("XmlReplay: "+replay); return replay; } @@ -70,7 +73,8 @@ public class XmlReplayTest { String thisDir = Tools.glue(relToServicesRoot, "/", "IntegrationTests"); String pwd = (new File(thisDir)).getCanonicalPath(); //System.out.println("createXmlReplayUsingIntegrationTestsModule.pwd: "+pwd); - XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE); + XmlReplay replay = new XmlReplay(pwd+XMLREPLAY_REL_DIR_TO_MODULE, + pwd+XMLREPLAY_REL_DIR_REPORTS_TO_MODULE); //System.out.println("XmlReplay: "+replay); return replay; } diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/TEST-REPORTS/reports-include.css b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/_includes/reports-include.css similarity index 100% rename from services/IntegrationTests/src/test/resources/test-data/xmlreplay/TEST-REPORTS/reports-include.css rename to services/IntegrationTests/src/test/resources/test-data/xmlreplay/_includes/reports-include.css diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/TEST-REPORTS/reports-include.js b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/_includes/reports-include.js similarity index 100% rename from services/IntegrationTests/src/test/resources/test-data/xmlreplay/TEST-REPORTS/reports-include.js rename to services/IntegrationTests/src/test/resources/test-data/xmlreplay/_includes/reports-include.js diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/0-note.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/0-note.xml new file mode 100644 index 000000000..8ac99515c --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/0-note.xml @@ -0,0 +1,9 @@ + + + + XmlReplay NOTE + ${content} + entryDate-1306297181479 + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml index aecbeaa4a..0477ff257 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml @@ -18,15 +18,11 @@ ${itemCSID} Locationitem - Item - 1111 ${parentCSID} ${parentUri} Locationitem - 0000-setting-error - Parent diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/4-locations_w_relations_mixed.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/4-locations_w_relations_mixed.xml new file mode 100755 index 000000000..3c79b2b2d --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/4-locations_w_relations_mixed.xml @@ -0,0 +1,37 @@ + + + + ${inAuthority} + ${shortIdentifier} + urn:cspace:org.collectionspace.demo:locationauthority:name(${authShortIdentifier}):location:name(${shortIdentifier})'${name}' + ${name} + false + true + + + + hasBroader + + ${childCSID} + Locationitem + + + ${itemCSID} + Locationitem + + + + hasBroader + + ${child2CSID} + Locationitem + + + ${itemCSID} + Locationitem + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy-dual-parents.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy-dual-parents.xml new file mode 100644 index 000000000..6ebd34339 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy-dual-parents.xml @@ -0,0 +1,219 @@ + + + + + + POST + /cspace-services/locationauthorities/ + location/hierarchy/1-authority.xml + + CSPACE3739LocationAuthority + LocationAuth1-displayName + + + + POST + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/ + location/hierarchy/2-item.xml + + ${LocationAuth1.CSID} + CSPACE3739LocationAuthority + Shelf1 + Shelf 1 + + + + POST + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/ + location/hierarchy/2-item.xml + + ${LocationAuth1.CSID} + CSPACE3739LocationAuthority + Shelf2 + Shelf 2 + + + + POST + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/ + location/hierarchy/2-item.xml + + ${LocationAuth1.CSID} + CSPACE3739LocationAuthority + Shelf3 + Shelf 3 + + + + + POST + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/ + location/hierarchy/2-item.xml + + ${LocationAuth1.CSID} + CSPACE3739LocationAuthority + Aisle3 + Aisle 3 + + + + + POST + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/ + location/hierarchy/3-locations_w_relations.xml + + ${LocationAuth1.CSID} + CSPACE3739LocationAuthority + Cabinet1 + Cabinet 1 + ${LocationParent.CSID} + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/${LocationParent.CSID} + ${LocationChild1.CSID} + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/${LocationChild1.CSID} + ${LocationChild2.CSID} + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/${LocationChild2.CSID} + ${LocationChild3.CSID} + /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/${LocationChild3.CSID} + + + + + POST + /cspace-services/dimensions/ + location/hierarchy/0-note.xml + + + LocationAuth1: ${LocationAuth1.CSID} + | Location: ${Location1.CSID} + | Parent: ${LocationParent.CSID} + | Children: + | 1: ${LocationChild1.CSID} + | 2: ${LocationChild2.CSID} + | 3: ${LocationChild3.CSID} + | Location2: ${Location2.CSID} + + + + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${Location1.CSID}?showRelations=true + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${LocationParent.CSID}?showRelations=true + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${LocationChild1.CSID}?showSiblings=true + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${Location1.CSID}?showAllRelations=true + + + + GET + /cspace-services/relations/ + + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${Location1.CSID}/hierarchy + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${LocationParent.CSID}/hierarchy + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${LocationChild1.CSID}/hierarchy?direction=parents + + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-mixed-hierarchy.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-mixed-hierarchy.xml new file mode 100644 index 000000000..058ab5b82 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-mixed-hierarchy.xml @@ -0,0 +1,88 @@ + + + + + + POST + /cspace-services/locationauthorities/ + location/hierarchy/1-authority.xml + + CSPACE4042LocationAuthority + LocationAuth1-displayName + + + + + POST + /cspace-services/locationauthorities/ + location/hierarchy/1-authority.xml + + CSPACE4042LocationAuthoritySecond + LocationAuth1-Second-Instance + + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID} + + + + GET + /cspace-services/locationauthorities/${LocationAuth2.CSID} + + + + POST + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/ + location/hierarchy/2-item.xml + + ${LocationAuth1.CSID} + CSPACE4042LocationAuthority + Shelf1 + Shelf 1 in LocationAuth1 + + + + + + + POST + /cspace-services/locationauthorities/${LocationAuth2.CSID}/items/ + location/hierarchy/2-item.xml + + ${LocationAuth2.CSID} + CSPACE4042LocationAuthoritySecond + Shelf2 + Shelf 2 in LocationAuth2 + + + + + POST + /cspace-services/locationauthorities/urn:cspace:name(CSPACE4042LocationAuthority)/items/ + location/hierarchy/4-locations_w_relations_mixed.xml + + ${LocationAuth1.CSID} + CSPACE4042LocationAuthority + Cabinet1 + Cabinet 1 + ${LocationChild1.CSID} + ${LocationChild2.CSID} + + + + + GET + /cspace-services/locationauthorities/${LocationAuth1.CSID}/items/${Location1.CSID}?showRelations=true + + + + diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java index b6be3b3bf..05689825d 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java @@ -34,6 +34,7 @@ public interface AuthorityItemJAXBSchema { final static String SHORT_DISPLAY_NAME_COMPUTED = "shortDisplayNameComputed"; final static String IN_AUTHORITY = "inAuthority"; final static String REF_NAME = "refName"; + final static String ORDER = "order"; final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String TERM_STATUS = "termStatus"; final static String CSID = "csid"; diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index e97d2a646..2c293c42c 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -23,48 +23,18 @@ */ package org.collectionspace.services.common.vocabulary; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.List; - -import javax.management.relation.Relation; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.Encoded; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; - import org.collectionspace.services.client.IQueryManager; -import org.collectionspace.services.client.PayloadInputPart; -import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.common.document.JaxbUtils; -import org.collectionspace.services.common.relation.IRelationsManager; -import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; -import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; -import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; -import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; -import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.ServiceMessages; +import org.collectionspace.services.common.XmlTools; import org.collectionspace.services.common.api.RefName; +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.JaxRsContext; @@ -73,19 +43,20 @@ import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.RemoteServiceContext; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.document.BadRequestException; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.common.relation.IRelationsManager; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.security.UnauthorizedException; -import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; +import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; -import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.relation.RelationResource; -import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.util.HttpResponseCodes; @@ -93,13 +64,32 @@ import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; +import java.util.List; + /** * The Class AuthorityResource. */ @Consumes("application/xml") @Produces("application/xml") -public abstract class AuthorityResource extends - AbstractMultiPartCollectionSpaceResourceImpl { +public abstract class AuthorityResource + //extends ResourceBase { + extends AbstractMultiPartCollectionSpaceResourceImpl { protected Class authCommonClass; protected Class resourceClass; @@ -923,5 +913,31 @@ public abstract class AuthorityResource"; + try { + result = XmlTools.prettyPrint(result); + } catch (Exception e){ + } + return result; + } + + private static String dive(ServiceContext ctx, String itemcsid, String uri, boolean lookupFirstName) { + MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); + //Run getList() once as sent to get childListOuter: + queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value()); + queryParams.putSingle(IRelationsManager.SUBJECT_QP, null); + queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); + queryParams.putSingle(IRelationsManager.OBJECT_QP, itemcsid); + queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); + RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. + List childList = childListOuter.getRelationListItem(); + + StringBuffer sb = new StringBuffer(); + + if (lookupFirstName && childList.size() > 0) { + RelationsCommonList.RelationListItem firstItem = childList.get(0); + sb.append("" + firstItem.getObject().getUri() + "\r\n"); + sb.append("" + uri + "\r\n"); + sb.append("" + firstItem.getObject().getName() + "" + firstItem.getObject().getNumber() + "\r\n"); + } else { + sb.append("" + uri + "\r\n"); + } + sb.append("" + itemcsid + "\r\n"); + sb.append("\r\n"); + for (RelationsCommonList.RelationListItem item : childList) { + RelationsDocListItem parent = item.getObject(); + RelationsDocListItem child = item.getSubject(); + String childCSID = child.getCsid(); + String childURI = child.getUri(); + sb.append("\r\n"); + sb.append("" +parent.getUri() + "\r\n"); + sb.append(" " + child.getName() + "" + child.getNumber() + "\r\n"); + String s = dive(ctx, childCSID, childURI, false); + sb.append(s); + sb.append("\r\n"); + } + sb.append("\r\n"); + return sb.toString(); + } + + public static String surface(ServiceContext ctx, String itemcsid, String uri) { + String result = surface(ctx, itemcsid, uri, true).resultBuffer.toString(); + result = ""+result+""; + try { + result = XmlTools.prettyPrint(result); + } catch (Exception e){ + } + return result; + } + private static class SurfaceResultStruct { + public StringBuffer resultBuffer; + public boolean noParents = false; + } + private static SurfaceResultStruct surface(ServiceContext ctx, String itemcsid, String uri, boolean first) { + MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); + //Run getList() once as sent to get parentListOuter: + queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value()); + queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemcsid); + queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); + queryParams.putSingle(IRelationsManager.OBJECT_QP, null); + queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); + RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. + List parentList = parentListOuter.getRelationListItem(); + + StringBuffer sbOuter = new StringBuffer(); + SurfaceResultStruct resultStruct = new SurfaceResultStruct(); + resultStruct.resultBuffer = sbOuter; + + + sbOuter.append("" + uri + "\r\n"); + sbOuter.append("" + itemcsid + "\r\n"); + + StringBuffer sb = new StringBuffer(); + + String name = ""; + String otherNames=""; + String number = ""; + String otherNumbers = ""; + + sb.append("\r\n"); + if (parentList.size()==0){ + resultStruct.noParents = true; + } + for (RelationsCommonList.RelationListItem item : parentList) { + resultStruct.noParents = false; + RelationsDocListItem parent = item.getObject(); + RelationsDocListItem child = item.getSubject(); + String parentCSID =parent.getCsid(); + String parentURI = parent.getUri(); + + String aName = child.getName(); + String aNumber = child.getNumber(); + if (name.length()>0 && (!name.equals(aName))){ + otherNames = otherNames+";"+aName; + } else { + name = aName; + } + if (number.length()>0 && (!number.equals(aNumber))){ + otherNumbers = otherNumbers+";"+aNumber; + } else { + number = aName; + } + + sb.append("\r\n"); + //sb.append("" +parentURI + "\r\n"); + + SurfaceResultStruct struct = surface(ctx, parentCSID, parentURI, false); + StringBuffer surfaceResult = struct.resultBuffer; + + if (struct.noParents){ + //when there are no more parents, there is no way to look up the name and number, so use this trick: + sb.append("" + parent.getName() + "" + parent.getNumber() + "\r\n"); + } + + sb.append(surfaceResult); + sb.append("\r\n"); + } + sb.append("\r\n"); + + + if (name.length()>0)sbOuter.append(" " +name + "\r\n"); + if (otherNames.length()>0) sbOuter.append(" " +otherNames + "\r\n"); + + if (number.length()>0) sbOuter.append("" +number + "\r\n"); + if (otherNumbers.length()>0) sbOuter.append(" " +otherNumbers + "\r\n"); + + sbOuter.append(sb); + + return resultStruct; + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java b/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java index e97ff9d96..6a344e80f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java +++ b/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java @@ -101,9 +101,14 @@ public class XmlTools { return doc; } + public static String prettyPrint(String xml) throws Exception { + Document doc = textToXMLDocument(xml); + return prettyPrint(doc, " "); + } + public static String prettyPrint(Document document) { - return prettyPrint(document, null); - } + return prettyPrint(document, null); + } public static String prettyPrint(Document document, String indentString) { String prettyHTML; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 743c4b4b5..d4fb43596 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -121,7 +121,11 @@ public abstract class RemoteDocumentModelHandlerImpl Map unQObjectProperties = extractPart(docModel, partLabel, partMeta); addOutputPart(unQObjectProperties, partLabel, partMeta); } catch (Throwable t){ - System.out.println("===============================\r\nUnable to addOutputPart: "+partLabel+" error: "+t); + + System.out.println("===============================\r\nUnable to addOutputPart: "+partLabel + +" in serviceContextPath: "+this.getServiceContextPath() + +" with URI: "+this.getServiceContext().getUriInfo().getPath() + +" error: "+t); } } } else { diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd index 7202c731e..a38f369e9 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd @@ -27,6 +27,6 @@ - + diff --git a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd index add19438f..dca9978f2 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd @@ -1,35 +1,36 @@ - + - - - + + + - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - @@ -43,30 +44,32 @@ - + - + minOccurs="1"/> + + + minOccurs="1"/> + minOccurs="1"/> + minOccurs="1"/> - + - + diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java index 0d751ac67..54683b208 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java @@ -68,7 +68,7 @@ public class VocabularyItemDocumentModelHandler DocumentWrapper wrapDoc) throws Exception { VocabularyitemsCommonList coList = extractPagingInfo(new VocabularyitemsCommonList(), wrapDoc); AbstractCommonList commonList = (AbstractCommonList) coList; - commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid"); + commonList.setFieldsReturned("displayName|refName|shortIdentifier|order|uri|csid"); List list = coList.getVocabularyitemListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); @@ -80,8 +80,10 @@ public class VocabularyItemDocumentModelHandler AuthorityItemJAXBSchema.DISPLAY_NAME)); ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel, AuthorityItemJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, - AuthorityItemJAXBSchema.REF_NAME)); + ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.REF_NAME)); + ilistItem.setOrder((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.ORDER)); String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri("/vocabularies/" + inAuthority + "/items/" + id); ilistItem.setCsid(id); -- 2.47.3