From: Richard Millet Date: Sat, 28 Aug 2010 00:12:09 +0000 (+0000) Subject: CSPACE-2338: Develop Basic Object Exit Code developed by Laramie and submitted as... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=dfb487991d0ba90ec45d90a5b040a1c9eca198ab;p=tmp%2Fjakarta-migration.git CSPACE-2338: Develop Basic Object Exit Code developed by Laramie and submitted as a patch. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java new file mode 100644 index 000000000..6193df815 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -0,0 +1,272 @@ +package org.collectionspace.services.common; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.context.MultipartServiceContextImpl; +import org.collectionspace.services.common.context.ServiceBindingUtils; +import org.collectionspace.services.common.context.ServiceContext; +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.IQueryManager; +import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.nuxeo.ecm.core.api.DocumentModel; + +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import java.util.List; + +/** + * $LastChangedRevision: $ + * $LastChangedDate: $ + * Author: laramie + */ +public abstract class ResourceBase +extends AbstractMultiPartCollectionSpaceResourceImpl { + + public static final String CREATE = "create"; + public static final String READ = "get"; + public static final String UPDATE = "update"; + public static final String DELETE = "delete"; + public static final String LIST = "list"; + + public void ensureCSID(String csid, String crudType) throws WebApplicationException { + if (logger.isDebugEnabled()) { + logger.debug(crudType+" for "+getClass().getName()+" with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error(crudType+" for " + getClass().getName() + " missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST) + .entity("update failed on " + getClass().getName() + " csid=" + csid) + .type("text/plain") + .build(); + throw new WebApplicationException(response); + } + } + + protected WebApplicationException bigReThrow(Exception e, String serviceMsg) + throws WebApplicationException { + return bigReThrow(e, serviceMsg, ""); + } + + protected WebApplicationException bigReThrow(Exception e, String serviceMsg, String csid) + throws WebApplicationException { + Response response; + if (logger.isDebugEnabled()) { + logger.debug(getClass().getName(), e); + } + if (e instanceof UnauthorizedException) { + response = Response.status(Response.Status.UNAUTHORIZED) + .entity(serviceMsg + e.getMessage()) + .type("text/plain") + .build(); + return new WebApplicationException(response); + } else if (e instanceof DocumentNotFoundException) { + response = Response.status(Response.Status.NOT_FOUND) + .entity(serviceMsg + " on "+getClass().getName()+" csid=" + csid) + .type("text/plain") + .build(); + return new WebApplicationException(response); + } else { //e is now instanceof Exception + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(serviceMsg) + .type("text/plain") + .build(); + return new WebApplicationException(response); + } + } + + //======================= CREATE ==================================================== + + @POST + public Response create(MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(input); + DocumentHandler handler = createDocumentHandler(ctx); + UriBuilder path = UriBuilder.fromResource(this.getClass()); + return create(input, ctx, handler, path); //==> CALL implementation method, which subclasses may override. + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.CREATE_FAILED); + } + } + + /** Subclasses may override this overload, which gets called from @see #create(MultipartInput) */ + protected Response create(MultipartInput input, + ServiceContext ctx, + DocumentHandler handler, + UriBuilder path) + throws Exception { + String csid = getRepositoryClient(ctx).create(ctx, handler); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } + + //======================= UPDATE ==================================================== + + @PUT + @Path("{csid}") + public MultipartOutput update(@PathParam("csid") String csid, MultipartInput theUpdate) { + ensureCSID(csid, UPDATE); + try { + ServiceContext ctx = createServiceContext(theUpdate); + DocumentHandler handler = createDocumentHandler(ctx); + return update(csid, theUpdate, ctx, handler); //==> CALL implementation method, which subclasses may override. + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid); + } + } + + /** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput) */ + protected MultipartOutput update(String csid, + MultipartInput theUpdate, + ServiceContext ctx, + DocumentHandler handler) + throws Exception { + getRepositoryClient(ctx).update(ctx, csid, handler); + return (MultipartOutput) ctx.getOutput(); + } + + //======================= DELETE ==================================================== + + @DELETE + @Path("{csid}") + public Response delete(@PathParam("csid") String csid) { + ensureCSID(csid, DELETE); + try { + ServiceContext ctx = createServiceContext(); + return delete(csid, ctx); //==> CALL implementation method, which subclasses may override. + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid); + } + } + + /** subclasses may override this method, which is called from #delete(String) + * which handles setup of ServiceContext, and does Exception handling. */ + protected Response delete(String csid, ServiceContext ctx) + throws Exception { + getRepositoryClient(ctx).delete(ctx, csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } + + + //======================= GET ==================================================== + + @GET + @Path("{csid}") + public MultipartOutput get(@PathParam("csid") String csid) { + ensureCSID(csid, READ); + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + MultipartOutput result = get(csid, ctx, handler);// ==> CALL implementation method, which subclasses may override. + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); + } + } + + /** subclasses may override this method, which is called from #get(String) + * which handles setup of ServiceContext and DocumentHandler, and Exception handling.*/ + public MultipartOutput get(String csid, + ServiceContext ctx, + DocumentHandler handler) + throws Exception { + getRepositoryClient(ctx).get(ctx, csid, handler); + return (MultipartOutput) ctx.getOutput(); + } + + //======================= GET without csid. List, search, etc. ===================================== + + @GET + @Produces("application/xml") + public AbstractCommonList getList (@Context UriInfo ui, + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { + MultivaluedMap queryParams = ui.getQueryParameters(); + if (keywords != null) { + return search(queryParams, keywords); + } else { + return getList(queryParams); + } + } + + protected AbstractCommonList getList(MultivaluedMap queryParams) { + try { + ServiceContext ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getFiltered(ctx, handler); + return (AbstractCommonList)handler.getCommonPartList(); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.LIST_FAILED); + } + } + + + protected AbstractCommonList search(MultivaluedMap queryParams, String keywords) { + try { + ServiceContext ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + // perform a keyword search + if (keywords != null && !keywords.isEmpty()) { + String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); + DocumentFilter documentFilter = handler.getDocumentFilter(); + documentFilter.setWhereClause(whereClause); + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + } + } + getRepositoryClient(ctx).getFiltered(ctx, handler); + return (AbstractCommonList) handler.getCommonPartList(); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.SEARCH_FAILED); + } + } + + @Deprecated + public AbstractCommonList getList(List csidList) { + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csidList, handler); + return (AbstractCommonList)handler.getCommonPartList(); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.LIST_FAILED); + } + } + + //======================== GET : getAuthorityRefs ======================================== + + @GET + @Path("{csid}/authorityrefs") + @Produces("application/xml") + public AuthorityRefList getAuthorityRefs( + @PathParam("csid") String csid, + @Context UriInfo ui) { + AuthorityRefList authRefList = null; + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); + DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); + DocumentModelHandler handler = (DocumentModelHandler)createDocumentHandler(ctx); + List authRefFields = + ((MultipartServiceContextImpl) ctx).getCommonPartPropertyValues( + ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES); + authRefList = handler.getAuthorityRefs(docWrapper, authRefFields); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.AUTH_REFS_FAILED, csid); + } + return authRefList; + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServletTools.java b/services/common/src/main/java/org/collectionspace/services/common/ServletTools.java new file mode 100644 index 000000000..87a909c3b --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/ServletTools.java @@ -0,0 +1,382 @@ +package org.collectionspace.services.common; + + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Enumeration; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ServletTools { + + public final static int BROWSER_NOT_SET = -1; + public final static int BROWSER_UNKNOWN = 0; + public final static int BROWSER_IE4 = 1; + public final static int BROWSER_NETSCAPE_COMPATIBLE = 20; + public final static int BROWSER_NETSCAPE_4 = 21; + public final static int BROWSER_NETSCAPE_5 = 22; + public final static int BROWSER_NETSCAPE_6 = 23; + public final static int BROWSER_IE = 24; + public final static int BROWSER_DYNAMIDE_TEXT = 50; + + public final static String BROWSER_STRING_UNKNOWN = "*"; + public final static String BROWSER_STRING_IE = "IE"; + public final static String BROWSER_STRING_NETSCAPE_COMPATIBLE = "NS"; + + public final static String getBrowserStringFromID(int id){ + switch ( id ) { + case BROWSER_UNKNOWN : return BROWSER_STRING_UNKNOWN; + case BROWSER_IE : return BROWSER_STRING_IE; + case BROWSER_NETSCAPE_COMPATIBLE : return BROWSER_STRING_NETSCAPE_COMPATIBLE; + default: return BROWSER_STRING_UNKNOWN; + } + } + + /** Different from ServletRequest.getParameter in that this function will never return a null, always and empty string if param not found. + */ + public static String getParameterValue(HttpServletRequest request, String paramName){ + if (request == null){ + return ""; + } + String value = request.getParameter(paramName); + value = (value == null) ? "" : value; + return value; + } + + public static String getURL(HttpServletRequest request){ + if (request == null){ + return ""; + } + String qs = request.getQueryString(); + String qstr = (qs != null && qs.length() > 0) + ? "?"+qs + : ""; + return request.getRequestURI()+qstr; + } + + public static String getFullURL(HttpServletRequest request){ + return getProtoHostPort(request)+getURL(request); + } + + /** @return "http" or "https", without the "://" part. + */ + public static String getProto(HttpServletRequest request){ + if (request==null){ + return ""; + } + String prot = request.getAuthType(); + String protocol = prot != null && prot.equals("SSL") ? "https" : "http"; + return protocol; + } + + public static String getProtoHostPort(HttpServletRequest request){ + if (request==null){ + return ""; + } + String protocol = getProto(request); + int port = request.getServerPort(); + String portstr; + if ( protocol.equals("https") ) { + portstr = (port != 443) ? ":"+port : ""; + } else { + portstr = (port != 80) ? ":"+port : ""; + } + return protocol+"://"+request.getServerName()+portstr; + } + + public static String getProtoHostPort(java.net.URL url){ + if (url==null){ + return ""; + } + String protocol = url.getProtocol(); + int port = url.getPort(); + String portstr; + if ( protocol.equals("https") ) { + portstr = (port != 443) ? ":"+port : ""; + } else { + portstr = (port != 80) ? ":"+port : ""; + } + return protocol+"://"+url.getHost()+portstr; + } + + public static String decodeURLString(HttpServletRequest request, String paramName) throws UnsupportedEncodingException{ + if ( request == null ) { + return ""; + } + String value = request.getParameter(paramName); + return decodeURLString(value); + } + + public static String decodeURLString(String URLString) throws UnsupportedEncodingException{ + if ( URLString == null ) { + return ""; + } + return URLDecoder.decode(URLString, "UTF-8"); + } + + public static String encodeURLString(String s){ + return URLEncoder.encode(s); + } + + public static String dumpRequestInfo(HttpServletRequest request){ + return dumpRequestInfo(request, true, "#FFAD00", true); + } + + public static String dumpRequestInfo(HttpServletRequest request, boolean html, String headerColor, boolean dumpHeaders){ + if (request==null){ + return "NULL REQUEST"; + } + String result; + if (dumpHeaders){ + result = dumpRequestHeaders(request, html); + } else { + result = "URL: " + getFullURL(request); + } + + if ( html ) { + result = result + "\r\n
Params: "; + } else { + result = result + "\r\nParams: "; + } + result = result + dumpRequestParams(request, html, headerColor); + return result; + } + + public static String dumpRequestHeaders(HttpServletRequest request, boolean html){ + if (request==null){ + return "NULL REQUEST"; + } + String headers = ""; + String nl = html ? "\r\n
" : "\r\n"; + for(Enumeration headernames = request.getHeaderNames(); headernames.hasMoreElements();){ + String headername = (String)headernames.nextElement(); + headers += nl + headername+": "+request.getHeader(headername); + } + String result; + if ( html ) { + result = "
";
+        } else {
+            result = "";
+        }
+        result = result + "\r\nHeaders: "+ headers
+          +"\r\nmethod: " + request.getMethod()
+          +"\r\nProtocol: " + getProto(request)
+          +"\r\nURL: " +  getFullURL(request);
+          //+"\r\nQuery String: " +  getQueryString()
+          //+"\r\nContent: " + getContent();
+          if ( html ) {
+            result = result + "
"; + } + return result; + } + + public static String dumpRequestParams(HttpServletRequest request){ + return dumpRequestParams(request, true, "#FFAD00"); + } + public static String dumpRequestParams(HttpServletRequest request, boolean html, String headerColor){ + if (request==null){ + return "NULL REQUEST"; + } + StringBuffer result = new StringBuffer(); + if (html) result.append( "\n" + + "\n" + + ""); + Enumeration paramNames = request.getParameterNames(); + while(paramNames.hasMoreElements()) { + String paramName = (String)paramNames.nextElement(); + + if (html) result.append("\r\n\r\n"); + else result.append("\r\n"); + } + if (html) result.append("
Parameter NameParameter Value(s)
" + paramName + "\r\n"); + else result.append(paramName).append("="); + + String[] paramValues = request.getParameterValues(paramName); + if (paramValues.length == 1) { + String paramValue = paramValues[0]; + if (paramValue.length() == 0){ + if (html) result.append("No Value"); + else result.append("\"\""); + } else { + if (html) result.append(paramValue); + else result.append('\"'+paramValue+'\"'); + } + } else { + if (html) result.append("
    "); + for(int i=0; i" + paramValues[i]+""); + else result.append('\"'+paramValues[i]+'\"'); + } + if (html) result.append("
"); + } + if (html) result.append("
"); + return result.toString(); + } + + + + public static class UserIDPassword { + public String user_id = ""; + public String password = ""; + } + + /* + + public String getUserName(){ + String remoteUserName = getRemoteUser().user_id; + if (remoteUserName.length() > 0){ + return remoteUserName; + } else { + String name = getFieldValue("USER"); + if ( name != null && name.length()>0 ) { + return name; + } + } + return ""; + } + */ + public static UserIDPassword getRemoteUser(HttpServletRequest request){ + return getRemoteUser(request.getHeader("Authorization")); + } + + protected static UserIDPassword getRemoteUser(String authString){ + UserIDPassword uip = new UserIDPassword(); + try { // Decode and decompose the Authorization headervalue + if (authString == null){ + return uip; + } + authString = authString.substring(6).trim(); + byte mydata[]; + sun.misc.BASE64Decoder base64 = new sun.misc.BASE64Decoder(); + mydata = base64.decodeBuffer(authString); + String loginInfo = new String(mydata); + int index = loginInfo.indexOf(":"); + if( index != -1 ){ + uip.password = loginInfo.substring(index +1); + uip.user_id = loginInfo.substring(0, index); + } + } catch(Exception e) { + //result will have empty user name + System.out.println("ServletTools.getRemoteUser() failed to obtain Authorization info"); + } + return uip; + } + + public static String browserVersion(HttpServletRequest request){ + String agent = request.getHeader("User-Agent"); + //Examples: + //curl/7.5.1 + //Mozilla/4.0 + //Mozilla/4.08 [en] (Win95; U ;Nav) + //Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; FMRCo cfg. 5.01.2.1a) + //Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; FMRCo cfg. 5.01.2.1a) + if ( agent == null ) { + return "null";//don't just return "" since this value may be used in a Tcl eval, and it would then disappear. + } + int start, stop; + if ( agent.indexOf("MSIE ") > -1 ) { + start = agent.indexOf("MSIE "); + stop = agent.indexOf(";", start); + stop = stop > -1 ? stop : agent.length(); //safety + return agent.substring(start+5, stop).trim(); + } else { + start = agent.indexOf("/"); + stop = agent.indexOf(" "); + stop = stop > -1 ? stop : agent.length(); //for JSSE, there is no space: User-Agent: Java1.3.0_02 + return agent.substring(start+1, stop).trim(); + } + } + + + /** + * Mozilla/4.79 [en] (Windows NT 5.0; U) + * Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 + * Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 + * Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705) + */ + public static int findBrowserID(HttpServletRequest request){ + String browserString = request.getHeader("User-Agent"); + if (browserString == null) + return BROWSER_UNKNOWN; + if (browserString.indexOf("MSIE") > -1) + return BROWSER_IE4; + int iMozilla = browserString.indexOf("Mozilla"); + if (iMozilla > -1){ + String ver = browserString.substring(iMozilla + ("Mozilla/".length()) ); + int iSpace = ver.indexOf(" "); + if (iSpace>-1){ + ver = ver.substring(0, iSpace); + } + try { + Double majorminor = new Double(ver); + if (majorminor.longValue()==4){ + return BROWSER_NETSCAPE_4; + } + if (majorminor.longValue()==5){ + return BROWSER_NETSCAPE_5; + } + if (majorminor.longValue()==6){ + return BROWSER_NETSCAPE_6; + } + } catch (Exception e) { + System.out.println("ERROR: silent after catching error converting browser minor version."+browserString); + return BROWSER_NETSCAPE_COMPATIBLE; + } + return BROWSER_NETSCAPE_COMPATIBLE; + } + return BROWSER_UNKNOWN; + } + + public static boolean isBrowserIE(int bid){ + return (bid == BROWSER_IE4 || bid == BROWSER_IE) ? true : false ; + } + + public static boolean isBrowserNS4x(int bid){ + return (bid == BROWSER_NETSCAPE_4) ; + } + + public static String getCookieValue(HttpServletRequest request, String name ){ + Cookie result = findCookie(request, name); + if ( result != null ) { + return result.getValue(); + } + return ""; + } + + public static Cookie findCookie(HttpServletRequest request, String name ){ + if (request == null || name == null) { + return null; + } + Cookie [] cookies = request.getCookies(); + if ( cookies == null ) { + return null; + } + int cookies_len = cookies.length; + for (int i=0; i < cookies_len; i++) { + Cookie cookie = cookies[i]; + if (cookie != null && name.equals(cookie.getName())){ + return cookie; + } + } + return null; + } + + public static Cookie setCookie(HttpServletResponse response, String name, String value){ + return setCookie(response, name, value, "/", 365*24*60*60); + } + + public static Cookie setCookie(HttpServletResponse response, String name, String value, String path, int maxAge){ + Cookie cookie = new javax.servlet.http.Cookie(name, value); + cookie.setMaxAge(maxAge); + cookie.setPath(path); + response.addCookie(cookie); + return cookie; + } + + + +} + diff --git a/services/objectexit/.project b/services/objectexit/.project new file mode 100644 index 000000000..c9150bb00 --- /dev/null +++ b/services/objectexit/.project @@ -0,0 +1,17 @@ + + + org.collectionspace.services.objectexit + + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/3rdparty/.project b/services/objectexit/3rdparty/.project new file mode 100644 index 000000000..1daa752fb --- /dev/null +++ b/services/objectexit/3rdparty/.project @@ -0,0 +1,17 @@ + + + org.collectionspace.services.objectexit.3rdparty + + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/3rdparty/build.xml b/services/objectexit/3rdparty/build.xml new file mode 100644 index 000000000..e40126e64 --- /dev/null +++ b/services/objectexit/3rdparty/build.xml @@ -0,0 +1,127 @@ + + + + objectexit service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.classpath b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.classpath new file mode 100644 index 000000000..199bbbbdb --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.project b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.project new file mode 100644 index 000000000..e970c860b --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.objectexit.3rdparty.nuxeo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/build.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/build.xml new file mode 100644 index 000000000..b3f141c03 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/build.xml @@ -0,0 +1,143 @@ + + + + objectexit nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/pom.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/pom.xml new file mode 100644 index 000000000..f5b81d3d7 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/pom.xml @@ -0,0 +1,38 @@ + + + + org.collectionspace.services + org.collectionspace.services.objectexit.3rdparty + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit.3rdparty.nuxeo + services.objectexit.3rdparty.nuxeo + jar + + ObjectExit Nuxeo Document Type + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/META-INF/MANIFEST.MF b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..8f3c23e5d --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: NuxeoCS +Bundle-SymbolicName: org.collectionspace.objectexit;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +Require-Bundle: org.nuxeo.runtime, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.core, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.platform.types.api, + org.nuxeo.ecm.platform.versioning.api, + org.nuxeo.ecm.platform.ui, + org.nuxeo.ecm.platform.forms.layout.client, + org.nuxeo.ecm.platform.publishing.api, + org.nuxeo.ecm.platform.ws +Provide-Package: org.collectionspace.objectexit +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..44924cf08 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,408 @@ + + + + + + ${bundle.fileName} + + + + + nuxeo.war + /nuxeo + + + + + + + + + + + + Seam Context Filter + /ws/FileManageWS + + + + Seam Context Filter + /DocumentManagerWS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{currentServerLocation.name}/#{currentTabAction.label} + + + + Create new document in #{currentDocument.name} + + + + Create new document in #{currentDocument.name} + + + + breadcrumb=command.user_dashboard + + + + breadcrumb=command.manageMembers + + + + breadcrumb=command.manageMembers + + + + breadcrumb=title.vocabularies + + + + breadcrumb=command.advancedSearch + + + + + + en + en_GB + en_US + fr + de + es + it + ar + ru + ja + vn + + + messages + + + + config/addWorkspace.jpdl.xml + + + + + + generic_error_page + /generic_error_page.xhtml + + + + + generic_message_page + /generic_message_page.xhtml + + + + + home + /nxstartup.xhtml + + + + + user_login + /login.xhtml + + + + + user_logout + /logout.xhtml + + + + + view_servers + /view_servers.xhtml + + + + + + + view_domains + /view_domains.xhtml + + + + + select_document_type + /select_document_type.xhtml + + + + + create_document + /create_document.xhtml + + + + + edit_document + /edit_document.xhtml + + + + + view_documents + /view_documents.xhtml + + + + + create_file + /create_file.xhtml + + + + + create_workspace_wizard + /createWorkspaceWizard.xhtml + + + + + send_email + /document_email.xhtml + + + + + + view_workspaces + /view_workspaces.xhtml + + + + + + create_domain + /create_domain.xhtml + + + + + + edit_domain + /edit_domain.xhtml + + + + + + create_workspace + /create_workspace.xhtml + + + + + + edit_workspace + /edit_workspace.xhtml + + + + + + + members_management + /members_management.xhtml + + + + + view_users + /view_users.xhtml + + + + + view_many_users + /view_many_users.xhtml + + + + + edit_user + /edit_user.xhtml + + + + + edit_user_password + /edit_user_password.xhtml + + + + + view_user + /view_user.xhtml + + + + + create_user + /create_user.xhtml + + + + + view_groups + /view_groups.xhtml + + + + + view_group + /view_group.xhtml + + + + + edit_group + /edit_group.xhtml + + + + + create_group + /create_group.xhtml + + + + + view_vocabularies + /view_vocabularies.xhtml + + + + + view_vocabulary + /view_vocabulary.xhtml + + + + + + + search_form + /search/search_form.xhtml + + + + + search_results_nxql + /search/search_results_nxql.xhtml + + + + + search_results_advanced + + /search/search_results_advanced.xhtml + + + + + + search_results_simple + /search/search_results_simple.xhtml + + + + + + + clipboard + /incl/clipboard.xhtml + + + + + user_dashboard + /user_dashboard.xhtml + + + + + select_workspace_template + /select_workspace_template.xhtml + + + + + pdf_generation_error + /pdf_generation_error.xhtml + + + + + mass_edit + /massedit_documents.xhtml + + + + + mass_edit_confirm + /massedit_documents_preview.xhtml + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..e91bd5848 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,29 @@ + + + + + + + view_documents + + + heading + collectionspace_core + objectexit + + + + + + ObjectExit + + + + + + ObjectExit + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..204f68091 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + objectExitNumber + borrower + borrowersContact + lendersAuthorizer + lendersAuthorizationDate + lendersContact + + + + + + + objectExitDate + loanReturnDate + loanRenewalApplicationDate + specialConditionsOfLoan + objectExitNote + loanPurpose + + + + + + + true + + objectExitNumber + + + dataInputText + + + + + + + + true + + borrower + + + dataInputText + + + + + + + + true + + borrowersContact + + + dataInputText + + + + + + + + true + + lendersAuthorizer + + + dataInputText + + + + + + + + true + + lendersAuthorizationDate + + + dataInputText + + + + + + + + true + + lendersContact + + + dataInputText + + + + + + + + true + + objectExitDate + + + dataInputText + + + + + + + + true + + loanReturnDate + + + dataInputText + + + + + + + + true + + loanRenewalApplicationDate + + + dataInputText + + + + + + + + true + + specialConditionsOfLoan + + + dataInputText + + + + + + + + true + + objectExitNote + + + dataInputText + + + + + + + + true + + loanPurpose + + + dataInputText + + + + + + diff --git a/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/schemas/objectexit_common.xsd b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/schemas/objectexit_common.xsd new file mode 100644 index 000000000..cc1cca155 --- /dev/null +++ b/services/objectexit/3rdparty/nuxeo-platform-cs-objectexit/src/main/resources/schemas/objectexit_common.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + diff --git a/services/objectexit/3rdparty/pom.xml b/services/objectexit/3rdparty/pom.xml new file mode 100644 index 000000000..c97a0e5ed --- /dev/null +++ b/services/objectexit/3rdparty/pom.xml @@ -0,0 +1,24 @@ + + + + org.collectionspace.services.objectexit + org.collectionspace.services + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit.3rdparty + services.objectexit.3rdparty + pom + + + 3rd party build for objectexit service + + + + nuxeo-platform-cs-objectexit + + diff --git a/services/objectexit/build.xml b/services/objectexit/build.xml new file mode 100644 index 000000000..7b251678c --- /dev/null +++ b/services/objectexit/build.xml @@ -0,0 +1,124 @@ + + + + objectexit service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/objectexit/client/.classpath b/services/objectexit/client/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/objectexit/client/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/objectexit/client/.project b/services/objectexit/client/.project new file mode 100644 index 000000000..eeb7f188e --- /dev/null +++ b/services/objectexit/client/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.objectexit.client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/client/pom.xml b/services/objectexit/client/pom.xml new file mode 100644 index 000000000..485e07a0e --- /dev/null +++ b/services/objectexit/client/pom.xml @@ -0,0 +1,90 @@ + + + + org.collectionspace.services + org.collectionspace.services.objectexit + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit.client + services.objectexit.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.objectexit.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.person.client + ${project.version} + + + + org.testng + testng + 5.6 + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-objectexit-client + + diff --git a/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java new file mode 100644 index 000000000..ae2e39719 --- /dev/null +++ b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java @@ -0,0 +1,149 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright (c) 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.client; + +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; +//import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.objectexit.ObjectexitCommonList; + +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * ObjectExitClient.java + * + * $LastChangedRevision: 2108 $ + * $LastChangedDate: 2010-05-17 18:25:37 -0700 (Mon, 17 May 2010) $ + * + */ +public class ObjectExitClient extends AbstractServiceClientImpl { + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + public String getServicePathComponent() { + return "objectexit"; //Laramie20100824 was objectexits, but label was a mismatch. + } + /** + * + */ +// private static final ObjectExitClient instance = new ObjectExitClient(); + /** + * + */ + private ObjectExitProxy objectexitProxy; + + /** + * + * Default constructor for ObjectExitClient class. + * + */ + public ObjectExitClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + setProxy(); + } + + @Override + public CollectionSpaceProxy getProxy() { + return this.objectexitProxy; + } + + /** + * allow to reset proxy as per security needs + */ + public void setProxy() { + if (useAuth()) { + objectexitProxy = ProxyFactory.create(ObjectExitProxy.class, + getBaseURL(), getHttpClient()); + } else { + objectexitProxy = ProxyFactory.create(ObjectExitProxy.class, + getBaseURL()); + } + } + + /** + * FIXME Comment this + * + * @return + */ +// public static ObjectExitClient getInstance() { +// return instance; +// } + + /** + * @return + * @see org.collectionspace.services.client.ObjectExitProxy#getObjectExit() + */ + public ClientResponse readList() { + return objectexitProxy.readList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.ObjectExitProxy#getAuthorityRefs(java.lang.String) + */ + public ClientResponse getAuthorityRefs(String csid) { + return objectexitProxy.getAuthorityRefs(csid); + } + + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.ObjectExitProxy#getObjectExit(java.lang.String) + */ + public ClientResponse read(String csid) { + return objectexitProxy.read(csid); + } + + /** + * @param objectexit + * @return + * + */ + public ClientResponse create(MultipartOutput multipart) { + return objectexitProxy.create(multipart); + } + + /** + * @param csid + * @param objectexit + * @return + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return objectexitProxy.update(csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.ObjectExitProxy#deleteObjectExit(java.lang.Long) + */ + public ClientResponse delete(String csid) { + return objectexitProxy.delete(csid); + } +} diff --git a/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitProxy.java b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitProxy.java new file mode 100644 index 000000000..efb8d842f --- /dev/null +++ b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitProxy.java @@ -0,0 +1,57 @@ +package org.collectionspace.services.client; + +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.core.Response; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.objectexit.ObjectexitCommonList; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; + +/** + * @version $Revision: 2108 $ + */ +@Path("/objectexit/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface ObjectExitProxy extends CollectionSpaceProxy { + + //(C)reate + @POST + ClientResponse create(MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse delete(@PathParam("csid") String csid); + + // List + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + // List Authority References + @GET + @Produces({"application/xml"}) + @Path("/{csid}/authorityrefs/") + ClientResponse getAuthorityRefs(@PathParam("csid") String csid); + +} diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java new file mode 100644 index 000000000..a4d6df42b --- /dev/null +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java @@ -0,0 +1,227 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.PersonJAXBSchema; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.ObjectExitClient; +import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.objectexit.ObjectexitCommon; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ObjectExitAuthRefsTest, carries out Authority References tests against a deployed and running ObjectExit (aka Loans Out) Service. + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class ObjectExitAuthRefsTest extends BaseServiceTest { + + private final String CLASS_NAME = ObjectExitAuthRefsTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + final String SERVICE_PATH_COMPONENT = "objectexit"; + final String PERSON_AUTHORITY_NAME = "ObjectexitPersonAuth"; + private String knownResourceId = null; + private List objectexitIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private String personAuthCSID = null; + private String depositorRefName = null; + private String exitDate = null; + private String exitNumber = null; + + @Override + protected CollectionSpaceClient getClientInstance() { + throw new UnsupportedOperationException(); //method not supported (or needed) in this test class + } + + @Override + protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + throw new UnsupportedOperationException(); //method not supported (or needed) in this test class + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createObjectExitInstance(String depositorRefName, String exitNumber, String exitDate) { + this.exitDate = exitDate; + this.exitNumber = exitNumber; + this.depositorRefName = depositorRefName; + ObjectexitCommon objectexit = new ObjectexitCommon(); + objectexit.setDepositor(depositorRefName); + objectexit.setExitNumber(exitNumber); + objectexit.setExitDate(exitDate); + + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(objectexit, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new ObjectExitClient().getCommonPartName()); + logger.debug("to be created, objectexit common: " + objectAsXmlString(objectexit, ObjectexitCommon.class)); + return multipart; + } + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void createWithAuthRefs(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + testSetup(STATUS_CREATED, ServiceRequestType.CREATE); + String identifier = createIdentifier(); // Submit the request to the service and store the response. + createPersonRefs();// Create all the person refs and entities + // Create a new Loans In resource. One or more fields in this resource will be PersonAuthority + // references, and will refer to Person resources by their refNames. + ObjectExitClient objectexitClient = new ObjectExitClient(); + MultipartOutput multipart = createObjectExitInstance(depositorRefName, "exitNumber-" + identifier, "exitDate-" + identifier); + ClientResponse res = objectexitClient.create(multipart); + assertStatusCode(res, testName); + if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. + knownResourceId = extractId(res); + } + objectexitIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup + } + + protected void createPersonRefs() { + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); + ClientResponse res = personAuthClient.create(multipart); + assertStatusCode(res, "createPersonRefs (not a surefire test)"); + personAuthCSID = extractId(res); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + // Create temporary Person resources, and their corresponding refNames by which they can be identified. + String csid = ""; + + csid = createPerson("Owen the Cur", "Owner", "owenCurOwner", authRefName); + personIdsCreated.add(csid); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Davenport", "Depositor", "davenportDepositor", authRefName); + personIdsCreated.add(csid); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + } + + protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + Map personInfo = new HashMap(); + personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); + personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); + ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + assertStatusCode(res, "createPerson (not a surefire test)"); + return extractId(res); + } + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) + public void readAndCheckAuthRefs(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + testSetup(STATUS_OK, ServiceRequestType.READ); + ObjectExitClient objectexitClient = new ObjectExitClient(); + ClientResponse res = objectexitClient.read(knownResourceId); + assertStatusCode(res, testName); + MultipartInput input = (MultipartInput) res.getEntity(); + ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, objectexitClient.getCommonPartName(), ObjectexitCommon.class); + Assert.assertNotNull(objectexit); + logger.debug(objectAsXmlString(objectexit, ObjectexitCommon.class)); + + // Check a couple of fields + Assert.assertEquals(objectexit.getDepositor(), depositorRefName); + Assert.assertEquals(objectexit.getExitDate(), exitDate); + Assert.assertEquals(objectexit.getExitNumber(), exitNumber); + + // Get the auth refs and check them + ClientResponse res2 = objectexitClient.getAuthorityRefs(knownResourceId); + assertStatusCode(res2, testName); + AuthorityRefList list = res2.getEntity(); + List items = list.getAuthorityRefItem(); + int numAuthRefsFound = items.size(); + logger.debug("Authority references, found " + numAuthRefsFound); + //Assert.assertEquals(numAuthRefsFound, NUM_AUTH_REFS_EXPECTED, + // "Did not find all expected authority references! " + + // "Expected " + NUM_AUTH_REFS_EXPECTED + ", found " + numAuthRefsFound); + if (logger.isDebugEnabled()) { + int i = 0; + for (AuthorityRefList.AuthorityRefItem item : items) { + logger.debug(testName + ": list-item[" + i + "] Field:" + item.getSourceField() + "= " + item.getAuthDisplayName() + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); + i++; + } + } + } + + /** + * Deletes all resources created by tests, after all tests have been run. + *

+ * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + @AfterClass(alwaysRun = true) + public void cleanUp() { + String noTest = System.getProperty("noTestCleanup"); + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + logger.debug("Skipping Cleanup phase ..."); + return; + } + logger.debug("Cleaning up temporary resources created for testing ..."); + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Delete Person resource(s) (before PersonAuthority resources). + for (String resourceId : personIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + personAuthClient.deleteItem(personAuthCSID, resourceId); + } + // Delete PersonAuthority resource(s). + // Note: Any non-success response is ignored and not reported. + if (personAuthCSID != null) { + personAuthClient.delete(personAuthCSID); + // Delete Loans In resource(s). + ObjectExitClient objectexitClient = new ObjectExitClient(); + for (String resourceId : objectexitIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + objectexitClient.delete(resourceId); + } + } + } + +} diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java new file mode 100644 index 000000000..0aa445ed1 --- /dev/null +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java @@ -0,0 +1,268 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.List; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.ObjectExitClient; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.objectexit.ObjectexitCommon; +import org.collectionspace.services.objectexit.ObjectexitCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service.

+ * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class ObjectExitServiceTest extends AbstractServiceTestImpl { + + private final String CLASS_NAME = ObjectExitServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + final String SERVICE_PATH_COMPONENT = "objectexit"; + private String knownResourceId = null; + + @Override + protected CollectionSpaceClient getClientInstance() { + return new ObjectExitClient(); + } + + @Override + protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + return response.getEntity(ObjectexitCommonList.class); + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void create(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupCreate(); + ObjectExitClient client = new ObjectExitClient(); + MultipartOutput multipart = createObjectExitInstance(createIdentifier()); + ClientResponse res = client.create(multipart); + assertStatusCode(res, testName); + if (knownResourceId == null) { + knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + for (int i = 0; i < 3; i++) { + create(testName); + } + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupRead(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.read(knownResourceId); + assertStatusCode(res, testName); + MultipartInput input = (MultipartInput) res.getEntity(); + ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); + Assert.assertNotNull(objectexit); + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) + public void readList(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupReadList(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.readList(); + ObjectexitCommonList list = res.getEntity(); + assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + List items = list.getObjectexitListItem(); + int i = 0; + for (ObjectexitCommonList.ObjectexitListItem item : items) { + logger.debug(testName + ": list-item[" + i + "] csid=" + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] objectExitNumber=" + item.getExitNumber()); + logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); + i++; + } + } + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupUpdate(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.read(knownResourceId); + assertStatusCode(res, testName); + logger.debug("got object to update with ID: " + knownResourceId); + MultipartInput input = (MultipartInput) res.getEntity(); + ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); + Assert.assertNotNull(objectexit); + + objectexit.setExitNumber("updated-" + objectexit.getExitNumber()); + logger.debug("Object to be updated:"+objectAsXmlString(objectexit, ObjectexitCommon.class)); + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(objectexit, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + res = client.update(knownResourceId, output); + assertStatusCode(res, testName); + input = (MultipartInput) res.getEntity(); + ObjectexitCommon updatedObjectExit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); + Assert.assertNotNull(updatedObjectExit); + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupUpdateNonExistent(); + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + ObjectExitClient client = new ObjectExitClient(); + MultipartOutput multipart = createObjectExitInstance(NON_EXISTENT_ID); + ClientResponse res = client.update(NON_EXISTENT_ID, multipart); + assertStatusCode(res, testName); + } + + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupDelete(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.delete(knownResourceId); + assertStatusCode(res, testName); + } + + // --------------------------------------------------------------- + // Failure outcome tests : means we expect response to fail, but test to succeed + // --------------------------------------------------------------- + + // Failure outcome + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupReadNonExistent(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.read(NON_EXISTENT_ID); + assertStatusCode(res, testName); + } + + // Failure outcome + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + logger.debug(testBanner(testName, CLASS_NAME)); + setupDeleteNonExistent(); + ObjectExitClient client = new ObjectExitClient(); + ClientResponse res = client.delete(NON_EXISTENT_ID); + assertStatusCode(res, testName); + } + + // Failure outcomes + // Placeholders until the tests below can be implemented. See Issue CSPACE-401. + + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + // --------------------------------------------------------------- + // Utility tests : tests of code used in tests above + // --------------------------------------------------------------- + + @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(knownResourceId); + int statusCode = submitRequest(method, url); + logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); + Assert.assertEquals(statusCode, EXPECTED_STATUS); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createObjectExitInstance(String exitNumber) { + String identifier = "objectexitNumber-" + exitNumber; + ObjectexitCommon objectexit = new ObjectexitCommon(); + objectexit.setExitNumber(identifier); + objectexit.setDepositor("urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'"); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(objectexit, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new ObjectExitClient().getCommonPartName()); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, objectexit common"); + logger.debug(objectAsXmlString(objectexit, ObjectexitCommon.class)); + } + + return multipart; + } +} diff --git a/services/objectexit/client/src/test/resources/log4j.properties b/services/objectexit/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/objectexit/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO diff --git a/services/objectexit/jaxb/.classpath b/services/objectexit/jaxb/.classpath new file mode 100644 index 000000000..557f8a4e0 --- /dev/null +++ b/services/objectexit/jaxb/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/objectexit/jaxb/.project b/services/objectexit/jaxb/.project new file mode 100644 index 000000000..5c5aa24f2 --- /dev/null +++ b/services/objectexit/jaxb/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.objectexit.jaxb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/jaxb/pom.xml b/services/objectexit/jaxb/pom.xml new file mode 100644 index 000000000..34dd42db2 --- /dev/null +++ b/services/objectexit/jaxb/pom.xml @@ -0,0 +1,47 @@ + + + + org.collectionspace.services.objectexit + org.collectionspace.services + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit.jaxb + services.objectexit.jaxb + + + + com.sun.xml.bind + jaxb-impl + + + org.jvnet.jaxb2-commons + property-listener-injector + + + org.jvnet.jaxb2_commons + runtime + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-objectexit-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitJAXBSchema.java b/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitJAXBSchema.java new file mode 100644 index 000000000..638b0b2ca --- /dev/null +++ b/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitJAXBSchema.java @@ -0,0 +1,15 @@ +/** + * + */ +package org.collectionspace.services; + +public interface ObjectexitJAXBSchema { + final static String OBJECT_EXIT_CURRENT_OWNER = "currentOwner"; + final static String OBJECT_EXIT_DEPOSITOR = "depositor"; + final static String OBJECT_EXIT_DATE = "exitDate"; + final static String OBJECT_EXIT_METHOD = "exitMethod"; + final static String OBJECT_EXIT_NOTE = "exitNote"; + final static String OBJECT_EXIT_NUMBER = "exitNumber"; + final static String OBJECT_EXIT_REASON = "exitReason"; + final static String OBJECT_EXIT_PACKING_NOTE = "packingNote"; +} diff --git a/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitListItemJAXBSchema.java b/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitListItemJAXBSchema.java new file mode 100644 index 000000000..a6874a6dc --- /dev/null +++ b/services/objectexit/jaxb/src/main/java/org/collectionspace/services/ObjectexitListItemJAXBSchema.java @@ -0,0 +1,15 @@ +package org.collectionspace.services; + +public interface ObjectexitListItemJAXBSchema { + final static String OBJECT_EXIT_CURRENT_OWNER = "currentOwner"; + final static String OBJECT_EXIT_DEPOSITOR = "depositor"; + final static String OBJECT_EXIT_DATE = "exitDate"; + final static String OBJECT_EXIT_METHOD = "exitMethod"; + final static String OBJECT_EXIT_NOTE = "exitNote"; + final static String OBJECT_EXIT_NUMBER = "exitNumber"; + final static String OBJECT_EXIT_REASON = "exitReason"; + final static String OBJECT_EXIT_PACKING_NOTE = "packingNote"; + + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/objectexit/jaxb/src/main/resources/objectexit_common.xsd b/services/objectexit/jaxb/src/main/resources/objectexit_common.xsd new file mode 100644 index 000000000..e691d90d4 --- /dev/null +++ b/services/objectexit/jaxb/src/main/resources/objectexit_common.xsd @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/objectexit/pom.xml b/services/objectexit/pom.xml new file mode 100644 index 000000000..ad8043b1e --- /dev/null +++ b/services/objectexit/pom.xml @@ -0,0 +1,24 @@ + + + + + org.collectionspace.services + org.collectionspace.services.main + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit + services.objectexit + pom + + + jaxb + service + 3rdparty + client + + + + diff --git a/services/objectexit/service/.classpath b/services/objectexit/service/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/objectexit/service/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/objectexit/service/.project b/services/objectexit/service/.project new file mode 100644 index 000000000..a39e1854a --- /dev/null +++ b/services/objectexit/service/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.objectexit.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/objectexit/service/pom.xml b/services/objectexit/service/pom.xml new file mode 100644 index 000000000..1f4f5d287 --- /dev/null +++ b/services/objectexit/service/pom.xml @@ -0,0 +1,117 @@ + + + + + org.collectionspace.services + org.collectionspace.services.objectexit + 0.9-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.objectexit.service + services.objectexit.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.objectexit.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.collectionobject.jaxb + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + 1.5.1-SNAPSHOT + + + jboss-remoting + jboss + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + + collectionspace-services-objectexit + + + diff --git a/services/objectexit/service/profiles.xml b/services/objectexit/service/profiles.xml new file mode 100644 index 000000000..347b9df22 --- /dev/null +++ b/services/objectexit/service/profiles.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/ObjectExitResource.java b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/ObjectExitResource.java new file mode 100644 index 000000000..b30910b6a --- /dev/null +++ b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/ObjectExitResource.java @@ -0,0 +1,78 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.objectexit; + +import org.collectionspace.services.common.ResourceBase; +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ServiceMain; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MultivaluedMap; +import java.util.List; + +@Path("/objectexit") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class ObjectExitResource extends ResourceBase { + + @Override + public String getServiceName(){ + return "objectexit"; + }; + + //FIXME retrieve client type from configuration + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + @Override + protected String getVersionString() { + final String lastChangeRevision = "$LastChangedRevision: 2108 $"; + return lastChangeRevision; + } + + @Override + public Class getCommonPartClass() { + return ObjectexitCommon.class; + } + + public Class getResourceClass() { + return this.getClass(); + } + + public ObjectexitCommonList getObjectexitList(MultivaluedMap queryParams) { + return (ObjectexitCommonList)getList(queryParams); + } + + @Deprecated + public ObjectexitCommonList getObjectexitList(List csidList) { + return (ObjectexitCommonList) getList(csidList); + } + + protected ObjectexitCommonList search(MultivaluedMap queryParams,String keywords) { + return (ObjectexitCommonList) super.search(queryParams, keywords); + } + + +} diff --git a/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitConstants.java b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitConstants.java new file mode 100644 index 000000000..2ddc216dd --- /dev/null +++ b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitConstants.java @@ -0,0 +1,35 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.objectexit.nuxeo; + +/** + * ObjectExitConstants specifies constants for the Loans Out service + * + */ +public class ObjectExitConstants { + + public final static String NUXEO_DOCTYPE = "ObjectExit"; + public final static String NUXEO_SCHEMA_NAME = "objectexit"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-ObjectExit"; +} diff --git a/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitDocumentModelHandler.java b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitDocumentModelHandler.java new file mode 100644 index 000000000..39b9a8c2a --- /dev/null +++ b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitDocumentModelHandler.java @@ -0,0 +1,162 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.objectexit.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.ObjectexitJAXBSchema; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.objectexit.ObjectexitCommon; +import org.collectionspace.services.objectexit.ObjectexitCommonList; +import org.collectionspace.services.objectexit.ObjectexitCommonList.ObjectexitListItem; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class ObjectExitDocumentModelHandler. + */ +public class ObjectExitDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + /** The logger. */ + private final Logger logger = LoggerFactory.getLogger(ObjectExitDocumentModelHandler.class); + + /** The objectexit. */ + private ObjectexitCommon objectexit; + + /** The objectexit list. */ + private ObjectexitCommonList objectexitList; + + + /** + * Gets the common part. + * + * @return the common part + */ + @Override + public ObjectexitCommon getCommonPart() { + return objectexit; + } + + /** + * Sets the common part. + * + * @param objectexit the new common part + */ + @Override + public void setCommonPart(ObjectexitCommon objectexit) { + this.objectexit = objectexit; + } + + /** + * Gets the common part list. + * + * @return the common part list + */ + @Override + public ObjectexitCommonList getCommonPartList() { + return objectexitList; + } + + /** + * Sets the common part list. + * + * @param objectexitList the new common part list + */ + @Override + public void setCommonPartList(ObjectexitCommonList objectexitList) { + this.objectexitList = objectexitList; + } + + /** + * Extract common part. + * + * @param wrapDoc the wrap doc + * @return the objectexit common + * @throws Exception the exception + */ + @Override + public ObjectexitCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + /** + * Fill common part. + * + * @param objectexitObject the objectexit object + * @param wrapDoc the wrap doc + * @throws Exception the exception + */ + @Override + public void fillCommonPart(ObjectexitCommon objectexitObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + /** + * Extract common part list. + * + * @param wrapDoc the wrap doc + * @return the objectexit common list + * @throws Exception the exception + */ + @Override + public ObjectexitCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + ObjectexitCommonList coList = extractPagingInfo(new ObjectexitCommonList(), wrapDoc); + List list = coList.getObjectexitListItem(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + ObjectexitListItem ilistItem = new ObjectexitListItem(); + + String label = getServiceContext().getCommonPartLabel(); + ilistItem.setExitNumber((String) docModel.getProperty(label, ObjectexitJAXBSchema.OBJECT_EXIT_NUMBER)); + ilistItem.setExitDate((String) docModel.getProperty(label, ObjectexitJAXBSchema.OBJECT_EXIT_DATE)); + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri(getServiceContextPath() + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + + return coList; + } + + /** + * Gets the q property. + * + * @param prop the prop + * @return the q property + */ + @Override + public String getQProperty(String prop) { + return ObjectExitConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } + +} + diff --git a/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitValidatorHandler.java b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitValidatorHandler.java new file mode 100644 index 000000000..60dc74e52 --- /dev/null +++ b/services/objectexit/service/src/main/java/org/collectionspace/services/objectexit/nuxeo/ObjectExitValidatorHandler.java @@ -0,0 +1,18 @@ +package org.collectionspace.services.objectexit.nuxeo; + +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.collectionspace.services.common.document.DocumentHandler.Action; + +public class ObjectExitValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("ObjectExitValidatorHandler executed."); + + } + +} diff --git a/services/objectexit/service/src/test/java/org/collectionspace/services/test/ObjectExitServiceTest.java b/services/objectexit/service/src/test/java/org/collectionspace/services/test/ObjectExitServiceTest.java new file mode 100644 index 000000000..bec77cb2c --- /dev/null +++ b/services/objectexit/service/src/test/java/org/collectionspace/services/test/ObjectExitServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.objectexit.ObjectExit; +//import org.collectionspace.services.objectexit.ObjectexitList; + +/** + * Placeholder for server-side testing of Loan Out service code. + * + * @version $Revision: 2108 $ + */ +public class ObjectExitServiceTest { + //empty +} diff --git a/services/objectexit/service/src/test/resources/log4j.xml b/services/objectexit/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/objectexit/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +