+++ /dev/null
-/**
- * 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.person;
-
-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.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-
-import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.ClientType;
-import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
-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.security.UnauthorizedException;
-import org.collectionspace.services.person.nuxeo.PersonAuthorityHandlerFactory;
-import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
-import org.collectionspace.services.person.nuxeo.PersonHandlerFactory;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.util.HttpResponseCodes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Path("/personauthorities")
-@Consumes("multipart/mixed")
-@Produces("multipart/mixed")
-public class PersonAuthorityResource extends AbstractCollectionSpaceResource {
-
- private final static String personAuthorityServiceName = "personauthorities";
- private final static String personServiceName = "persons";
- final Logger logger = LoggerFactory.getLogger(PersonAuthorityResource.class);
- //FIXME retrieve client type from configuration
- final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
-
- public PersonAuthorityResource() {
- // do nothing
- }
-
- @Override
- public String getServiceName() {
- return personAuthorityServiceName;
- }
-
- public String getItemServiceName() {
- return personServiceName;
- }
-
- /*
- public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
- RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
- ctx.setInput(input);
- return ctx;
- }
- */
- @Override
- public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = PersonAuthorityHandlerFactory.getInstance().getHandler(
- ctx.getRepositoryClientType().toString());
- docHandler.setServiceContext(ctx);
- if (ctx.getInput() != null) {
- Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
- if (obj != null) {
- docHandler.setCommonPart((PersonauthoritiesCommon) obj);
- }
- }
- return docHandler;
- }
-
- private DocumentHandler createItemDocumentHandler(
- ServiceContext ctx,
- String inAuthority) throws Exception {
- DocumentHandler docHandler = PersonHandlerFactory.getInstance().getHandler(
- ctx.getRepositoryClientType().toString());
- docHandler.setServiceContext(ctx);
- ((PersonDocumentModelHandler) docHandler).setInAuthority(inAuthority);
- if (ctx.getInput() != null) {
- Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
- PersonsCommon.class);
- if (obj != null) {
- docHandler.setCommonPart((PersonsCommon) obj);
- }
- }
- return docHandler;
- }
-
- @POST
- public Response createPersonAuthority(MultipartInput input) {
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
- DocumentHandler handler = createDocumentHandler(ctx);
- String csid = getRepositoryClient(ctx).create(ctx, handler);
- //personAuthorityObject.setCsid(csid);
- UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
- path.path("" + csid);
- Response response = Response.created(path.build()).build();
- return response;
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in createPersonAuthority", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- }
-
- @GET
- @Path("{csid}")
- public MultipartOutput getPersonAuthority(@PathParam("csid") String csid) {
- String idValue = null;
- if (csid == null) {
- logger.error("getPersonAuthority: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority with path(id)=" + csid);
- }
- MultipartOutput result = null;
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
- DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).get(ctx, csid, handler);
- result = (MultipartOutput) ctx.getOutput();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- if (result == null) {
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed, the requested PersonAuthority CSID:" + csid + ": was not found.").type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
-
- @GET
- @Produces("application/xml")
- public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) {
- PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList();
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- DocumentHandler handler = createDocumentHandler(ctx);
- DocumentFilter myFilter =
- DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
- String nameQ = queryParams.getFirst("refName");
- if (nameQ != null) {
- myFilter.setWhereClause("personauthorities_common:refName='" + nameQ + "'");
- }
- handler.setDocumentFilter(myFilter);
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in getPersonAuthorityList", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return personAuthorityObjectList;
- }
-
- @PUT
- @Path("{csid}")
- public MultipartOutput updatePersonAuthority(
- @PathParam("csid") String csid,
- MultipartInput theUpdate) {
- if (logger.isDebugEnabled()) {
- logger.debug("updatePersonAuthority with csid=" + csid);
- }
- if (csid == null || "".equals(csid)) {
- logger.error("updatePersonAuthority: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "update failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- MultipartOutput result = null;
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
- DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).update(ctx, csid, handler);
- result = (MultipartOutput) ctx.getOutput();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("caugth exception in updatePersonAuthority", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Update failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
-
- @DELETE
- @Path("{csid}")
- public Response deletePersonAuthority(@PathParam("csid") String csid) {
-
- if (logger.isDebugEnabled()) {
- logger.debug("deletePersonAuthority with csid=" + csid);
- }
- if (csid == null || "".equals(csid)) {
- logger.error("deletePersonAuthority: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
- getRepositoryClient(ctx).delete(ctx, csid);
- return Response.status(HttpResponseCodes.SC_OK).build();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("caught exception in deletePersonAuthority", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Delete failed on PersonAuthority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
-
- }
-
- /*************************************************************************
- * Person parts - this is a sub-resource of PersonAuthority
- *************************************************************************/
- @POST
- @Path("{csid}/items")
- public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) {
- try {
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
- UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
- path.path(parentcsid + "/items/" + itemcsid);
- Response response = Response.created(path.build()).build();
- return response;
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in createPerson", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- }
-
- @GET
- @Path("{csid}/items/{itemcsid}")
- public MultipartOutput getPerson(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid) {
- if (logger.isDebugEnabled()) {
- logger.debug("getPerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
- if (parentcsid == null || "".equals(parentcsid)) {
- logger.error("getPerson: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on Person csid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if (itemcsid == null || "".equals(itemcsid)) {
- logger.error("getPerson: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on Person itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- MultipartOutput result = null;
- try {
- // Note that we have to create the service context for the Items, not the main service
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- getRepositoryClient(ctx).get(ctx, itemcsid, handler);
- // TODO should we assert that the item is in the passed personAuthority?
- result = (MultipartOutput) ctx.getOutput();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("getPerson", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed on Person csid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("getPerson", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- if (result == null) {
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
-
- @GET
- @Path("{csid}/items")
- @Produces("application/xml")
- public PersonsCommonList getPersonList(
- @PathParam("csid") String parentcsid,
- @Context UriInfo ui) {
- PersonsCommonList personObjectList = new PersonsCommonList();
- try {
- // Note that docType defaults to the ServiceName, so we're fine with that.
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- DocumentFilter myFilter =
- DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
- myFilter.setWhereClause(
- "persons_common:inAuthority='" + parentcsid + "'");
- handler.setDocumentFilter(myFilter);
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- personObjectList = (PersonsCommonList) handler.getCommonPartList();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in getPersonList", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return personObjectList;
- }
-
- @PUT
- @Path("{csid}/items/{itemcsid}")
- public MultipartOutput updatePerson(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid,
- MultipartInput theUpdate) {
- if (logger.isDebugEnabled()) {
- logger.debug("updatePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
- if (parentcsid == null || "".equals(parentcsid)) {
- logger.error("updatePerson: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "update failed on Person parentcsid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if (itemcsid == null || "".equals(itemcsid)) {
- logger.error("updatePerson: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "update failed on Person=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- MultipartOutput result = null;
- try {
- // Note that we have to create the service context for the Items, not the main service
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- getRepositoryClient(ctx).update(ctx, itemcsid, handler);
- result = (MultipartOutput) ctx.getOutput();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("caugth exception in updatePerson", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Update failed on Person csid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
-
- @DELETE
- @Path("{csid}/items/{itemcsid}")
- public Response deletePerson(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid) {
- if (logger.isDebugEnabled()) {
- logger.debug("deletePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
- if (parentcsid == null || "".equals(parentcsid)) {
- logger.error("deletePerson: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on Person parentcsid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if (itemcsid == null || "".equals(itemcsid)) {
- logger.error("deletePerson: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on Person=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- try {
- // Note that we have to create the service context for the Items, not the main service
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
- getRepositoryClient(ctx).delete(ctx, itemcsid);
- return Response.status(HttpResponseCodes.SC_OK).build();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("caught exception in deletePerson", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Delete failed on Person itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
-
- }
-}
+++ /dev/null
-/**
- * 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.person.nuxeo;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.collectionspace.services.PersonAuthorityJAXBSchema;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.person.PersonauthoritiesCommon;
-import org.collectionspace.services.person.PersonauthoritiesCommonList;
-import org.collectionspace.services.person.PersonauthoritiesCommonList.PersonauthorityListItem;
-
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
-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;
-
-/**
- * PersonAuthorityDocumentModelHandler
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
- */
-public class PersonAuthorityDocumentModelHandler
- extends RemoteDocumentModelHandler<PersonauthoritiesCommon, PersonauthoritiesCommonList> {
-
- private final Logger logger = LoggerFactory.getLogger(PersonAuthorityDocumentModelHandler.class);
- /**
- * personAuthority is used to stash JAXB object to use when handle is called
- * for Action.CREATE, Action.UPDATE or Action.GET
- */
- private PersonauthoritiesCommon personAuthority;
- /**
- * personAuthorityList is stashed when handle is called
- * for ACTION.GET_ALL
- */
- private PersonauthoritiesCommonList personAuthorityList;
-
- @Override
- public void prepare(Action action) throws Exception {
- //no specific action needed
- }
-
- /**
- * getCommonPart get associated personAuthority
- * @return
- */
- @Override
- public PersonauthoritiesCommon getCommonPart() {
- return personAuthority;
- }
-
- /**
- * setCommonPart set associated personAuthority
- * @param personAuthority
- */
- @Override
- public void setCommonPart(PersonauthoritiesCommon personAuthority) {
- this.personAuthority = personAuthority;
- }
-
- /**
- * getCommonPartList get associated personAuthority (for index/GET_ALL)
- * @return
- */
- @Override
- public PersonauthoritiesCommonList getCommonPartList() {
- return personAuthorityList;
- }
-
- @Override
- public void setCommonPartList(PersonauthoritiesCommonList personAuthorityList) {
- this.personAuthorityList = personAuthorityList;
- }
-
- @Override
- public PersonauthoritiesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
- throws Exception {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void fillCommonPart(PersonauthoritiesCommon personAuthorityObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public PersonauthoritiesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
- DocumentModelList docList = wrapDoc.getWrappedObject();
-
- PersonauthoritiesCommonList coList = new PersonauthoritiesCommonList();
- List<PersonauthoritiesCommonList.PersonauthorityListItem> list = coList.getPersonauthorityListItem();
-
- //FIXME: iterating over a long list of documents is not a long term
- //strategy...need to change to more efficient iterating in future
- Iterator<DocumentModel> iter = docList.iterator();
- while(iter.hasNext()){
- DocumentModel docModel = iter.next();
- PersonauthorityListItem ilistItem = new PersonauthorityListItem();
- ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
- PersonAuthorityJAXBSchema.DISPLAY_NAME));
- ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
- PersonAuthorityJAXBSchema.REF_NAME));
- ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
- PersonAuthorityJAXBSchema.VOCAB_TYPE));
- String id = NuxeoUtils.extractId(docModel.getPathAsString());
- ilistItem.setUri(getServiceContextPath() + id);
- ilistItem.setCsid(id);
- list.add(ilistItem);
- }
-
- return coList;
- }
-
- /**
- * getQProperty converts the given property to qualified schema property
- * @param prop
- * @return
- */
- @Override
- public String getQProperty(String prop) {
- return PersonAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
- }
-}
-
+++ /dev/null
-/**
- * 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.person.nuxeo;
-
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.collectionspace.services.PersonJAXBSchema;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-import org.collectionspace.services.person.PersonsCommon;
-import org.collectionspace.services.person.PersonsCommonList;
-import org.collectionspace.services.person.PersonsCommonList.PersonListItem;
-import org.nuxeo.ecm.core.api.DocumentModel;
-import org.nuxeo.ecm.core.api.DocumentModelList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * PersonDocumentModelHandler
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
- */
-public class PersonDocumentModelHandler
- extends RemoteDocumentModelHandler<PersonsCommon, PersonsCommonList> {
-
- private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class);
- /**
- * person is used to stash JAXB object to use when handle is called
- * for Action.CREATE, Action.UPDATE or Action.GET
- */
- private PersonsCommon person;
- /**
- * personList is stashed when handle is called
- * for ACTION.GET_ALL
- */
- private PersonsCommonList personList;
-
- /**
- * inAuthority is the parent OrgAuthority for this context
- */
- private String inAuthority;
-
- public String getInAuthority() {
- return inAuthority;
- }
-
- public void setInAuthority(String inAuthority) {
- this.inAuthority = inAuthority;
- }
-
- @Override
- public void prepare(Action action) throws Exception {
- //no specific action needed
- }
-
- /* Override handleGet so we can deal with defaulting the displayName
- * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
- */
- @Override
- public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- DocumentModel docModel = wrapDoc.getWrappedObject();
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME);
- if(displayName == null) {
- docModel.setProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME, prepareDefaultDisplayName(docModel));
- }
- super.handleGet(wrapDoc);
- }
-
- private String prepareDefaultDisplayName(DocumentModel docModel) throws Exception {
- StringBuilder newStr = new StringBuilder();
- String part = null;
- final String sep = " ";
- final String dateSep = "-";
- List<String> nameStrings =
- Arrays.asList(PersonJAXBSchema.FORE_NAME, PersonJAXBSchema.MIDDLE_NAME,
- PersonJAXBSchema.SUR_NAME);
- boolean firstAdded = false;
- for(String partStr : nameStrings ){
- if(null != (part = (String)
- docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), partStr ))) {
- if(firstAdded) {
- newStr.append(sep);
- }
- newStr.append(part);
- firstAdded = true;
- }
- }
- // Now we add the dates. In theory could have dates with no name, but that is their problem.
- boolean foundBirth = false;
- if(null != (part = (String)
- docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.BIRTH_DATE ))) {
- if(firstAdded) {
- newStr.append(sep);
- }
- newStr.append(part);
- newStr.append(dateSep); // Put this in whether there is a death date or not
- foundBirth = true;
- }
- if(null != (part = (String)
- docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DEATH_DATE ))) {
- if(!foundBirth) {
- if(firstAdded) {
- newStr.append(sep);
- }
- newStr.append(dateSep);
- }
- newStr.append(part);
- }
- return newStr.toString();
- }
-
- /**
- * getCommonPart get associated person
- * @return
- */
- @Override
- public PersonsCommon getCommonPart() {
- return person;
- }
-
- /**
- * setCommonPart set associated person
- * @param person
- */
- @Override
- public void setCommonPart(PersonsCommon person) {
- this.person = person;
- }
-
- /**
- * getCommonPartList get associated person (for index/GET_ALL)
- * @return
- */
- @Override
- public PersonsCommonList getCommonPartList() {
- return personList;
- }
-
- @Override
- public void setCommonPartList(PersonsCommonList personList) {
- this.personList = personList;
- }
-
- @Override
- public PersonsCommon extractCommonPart(DocumentWrapper wrapDoc)
- throws Exception {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void fillCommonPart(PersonsCommon personObject, DocumentWrapper wrapDoc) throws Exception {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public PersonsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
- throws Exception {
- PersonsCommonList coList = new PersonsCommonList();
- try{
- DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
-
- List<PersonsCommonList.PersonListItem> list =
- coList.getPersonListItem();
-
- //FIXME: iterating over a long list of documents is not a long term
- //strategy...need to change to more efficient iterating in future
- Iterator<DocumentModel> iter = docList.iterator();
- while(iter.hasNext()){
- DocumentModel docModel = iter.next();
- PersonListItem ilistItem = new PersonListItem();
- // We look for a set display name, and fall back to teh short name if there is none
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME);
- if(displayName == null)
- displayName = prepareDefaultDisplayName(docModel);
- ilistItem.setDisplayName( displayName );
- ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.REF_NAME));
- String id = NuxeoUtils.extractId(docModel.getPathAsString());
- ilistItem.setUri("/personauthorities/"+inAuthority+"/items/" + id);
- ilistItem.setCsid(id);
- list.add(ilistItem);
- }
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception in extractCommonPartList", e);
- }
- throw e;
- }
- return coList;
- }
-
- /**
- * getQProperty converts the given property to qualified schema property
- * @param prop
- * @return
- */
- @Override
- public String getQProperty(String prop) {
- return PersonConstants.NUXEO_SCHEMA_NAME + ":" + prop;
- }
-}
-