From: Michael Ritter Date: Sat, 23 Nov 2024 00:02:36 +0000 (-0700) Subject: DRYD-1351: API For Supporting Create Page Update (#433) X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=d6dc41b9641c8fa113c96151a1be467bb34165f1;p=tmp%2Fjakarta-migration.git DRYD-1351: API For Supporting Create Page Update (#433) * Add new endpoint /servicegroups/:group/tags * Add servicetag query parameter to /servicegroups/:group * Apply spotless --- diff --git a/services/servicegroup/jaxb/src/main/resources/servicegroup_common.xsd b/services/servicegroup/jaxb/src/main/resources/servicegroup_common.xsd index fc2f45a74..42a669551 100644 --- a/services/servicegroup/jaxb/src/main/resources/servicegroup_common.xsd +++ b/services/servicegroup/jaxb/src/main/resources/servicegroup_common.xsd @@ -11,34 +11,31 @@ $LastChangedDate: 2010-06-02 16:03:51 -0700 (Wed, 02 Jun 2010) $ --> - - - - + + + + + + + + + - - - - - - - - - - + - - - + + + + + diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java index e18cc3ce7..728cc9e91 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java @@ -2,19 +2,19 @@ * 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. @@ -25,14 +25,24 @@ package org.collectionspace.services.servicegroup; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; - +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import javax.xml.parsers.ParserConfigurationException; import org.collectionspace.services.ServiceGroupListItemJAXBSchema; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ServiceGroupClient; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.NuxeoBasedResource; @@ -48,58 +58,45 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.ServiceContextFactory; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.query.QueryManager; -import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; -import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; -import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm; import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.config.service.ServiceObjectType; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.client.java.CommonList; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentFilter; import org.collectionspace.services.servicegroup.nuxeo.ServiceGroupDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - @Path(ServiceGroupClient.SERVICE_PATH) @Produces({"application/xml"}) @Consumes({"application/xml"}) public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private final static boolean EXCLUDE_AUTHORITIES = false; - private final static boolean INCLUDE_AUTHORITIES = true; - + + private static final boolean EXCLUDE_AUTHORITIES = false; + private static final boolean INCLUDE_AUTHORITIES = true; + @Override - public String getServiceName(){ + public String getServiceName() { return ServiceGroupClient.SERVICE_NAME; } - public String getServicePathComponent(){ + public String getServicePathComponent() { return ServiceGroupClient.SERVICE_NAME.toLowerCase(); } @Override protected String getVersionString() { - final String lastChangeRevision = "$LastChangedRevision: 2108 $"; - return lastChangeRevision; + final String lastChangeRevision = "$LastChangedRevision: 2108 $"; + return lastChangeRevision; } @Override - //public Class getCommonPartClass() { public Class getCommonPartClass() { - try { - return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon");//.class; - } catch (ClassNotFoundException e){ + try { + return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon"); + } catch (ClassNotFoundException e) { return null; } } @@ -109,95 +106,94 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl svcGroups = new ArrayList(); - svcGroups.add("procedure"); - svcGroups.add("object"); - svcGroups.add("authority"); - // Fetch the list of groups from the tenant-bindings config, and prepare a list item - // for each one. - // We always declare this a full list, of the size that we are returning. - // Not quite in the spirit of what paging means, but tells callers not to ask for more. - list.setPageNum(0); - list.setPageSize(svcGroups.size()); - list.setItemsInPage(svcGroups.size()); - list.setTotalItems(svcGroups.size()); - String fields[] = new String[2]; - fields[0] = ServiceGroupListItemJAXBSchema.NAME; - fields[1] = ServiceGroupListItemJAXBSchema.URI; - commonList.setFieldsReturned(fields); - HashMap item = new HashMap(); - for(String groupName:svcGroups){ - item.put(ServiceGroupListItemJAXBSchema.NAME, groupName); - String uri = "/" + getServiceName().toLowerCase() + "/" + groupName; - item.put(ServiceGroupListItemJAXBSchema.URI, uri); - commonList.addItem(item); - item.clear(); - } - return list; + AbstractCommonList list = (AbstractCommonList) commonList; + ArrayList svcGroups = new ArrayList(); + svcGroups.add("procedure"); + svcGroups.add("object"); + svcGroups.add("authority"); + // Fetch the list of groups from the tenant-bindings config, and prepare a list item + // for each one. + // We always declare this a full list, of the size that we are returning. + // Not quite in the spirit of what paging means, but tells callers not to ask for more. + list.setPageNum(0); + list.setPageSize(svcGroups.size()); + list.setItemsInPage(svcGroups.size()); + list.setTotalItems(svcGroups.size()); + String fields[] = new String[2]; + fields[0] = ServiceGroupListItemJAXBSchema.NAME; + fields[1] = ServiceGroupListItemJAXBSchema.URI; + commonList.setFieldsReturned(fields); + HashMap item = new HashMap(); + for (String groupName : svcGroups) { + item.put(ServiceGroupListItemJAXBSchema.NAME, groupName); + String uri = "/" + getServiceName().toLowerCase() + "/" + groupName; + item.put(ServiceGroupListItemJAXBSchema.URI, uri); + commonList.addItem(item); + item.clear(); + } + return list; } catch (Exception e) { throw bigReThrow(e, ServiceMessages.LIST_FAILED); } - } - - //======================= GET ==================================================== - // NOTE that csid is not a good name for the specifier, but if we name it anything else, - // our AuthZ gets confused!!! + // ======================= GET ==================================================== + // NOTE that csid is not a good name for the specifier, but if we name it anything else our AuthZ gets confused!!! @GET @Path("{csid}") - public byte[] get( - @Context UriInfo ui, - @PathParam("csid") String groupname) { + public byte[] get(@Context UriInfo ui, @PathParam("csid") String groupname) { PoxPayloadOut result = null; ensureCSID(groupname, NuxeoBasedResource.READ); try { - ServiceContext ctx = createServiceContext(); - TenantBindingConfigReaderImpl tReader = - ServiceMain.getInstance().getTenantBindingConfigReader(); + ServiceContext ctx = createServiceContext(ui); + ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) createDocumentHandler(ctx); + TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); // We need to get all the procedures, authorities, and objects. - ArrayList groupsList = null; - if("common".equalsIgnoreCase(groupname)) { - groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); - } else { - groupsList = new ArrayList(); - groupsList.add(groupname); - } - List servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupsList); - if (servicebindings == null || servicebindings.isEmpty()) { - // 404 if there are no mappings. - Response response = Response.status(Response.Status.NOT_FOUND).entity( - ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(groupname)).type("text/plain").build(); + ArrayList groupsList = null; + if ("common".equalsIgnoreCase(groupname)) { + groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); + } else { + groupsList = new ArrayList(); + groupsList.add(groupname); + } + List bindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupsList); + if (bindings == null || bindings.isEmpty()) { + // 404 if there are no mappings. + Response response = Response.status(Response.Status.NOT_FOUND) + .entity(ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(groupname)) + .type("text/plain") + .build(); throw new CSWebApplicationException(response); } - //Otherwise, build the response with a list + // Otherwise, build the response with a list ServicegroupsCommon common = new ServicegroupsCommon(); common.setName(groupname); String uri = "/" + getServicePathComponent() + "/" + groupname; common.setUri(uri); result = new PoxPayloadOut(getServicePathComponent()); result.addPart("ServicegroupsCommon", common); - - ServicegroupsCommon.HasDocTypes wrapper = common.getHasDocTypes(); - if(wrapper==null) { - wrapper = new ServicegroupsCommon.HasDocTypes(); - common.setHasDocTypes(wrapper); - } - List hasDocTypes = wrapper.getHasDocType(); - for(ServiceBindingType binding:servicebindings) { - ServiceObjectType serviceObj = binding.getObject(); - if(serviceObj!=null) { - String docType = serviceObj.getName(); - hasDocTypes.add(docType); - } - } + + String queryTag = ctx.getQueryParams().getFirst(IQueryManager.TAG_QUERY_PARAM); + ServicegroupsCommon.HasDocTypes wrapper = common.getHasDocTypes(); + if (wrapper == null) { + wrapper = new ServicegroupsCommon.HasDocTypes(); + common.setHasDocTypes(wrapper); + } + List hasDocTypes = wrapper.getHasDocType(); + for (ServiceBindingType binding : bindings) { + boolean includeDocType = handler.acceptServiceBinding(binding, queryTag); + + ServiceObjectType serviceObj = binding.getObject(); + if (includeDocType && serviceObj != null) { + String docType = serviceObj.getName(); + hasDocTypes.add(docType); + } + } } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, groupname); } @@ -205,72 +201,131 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl serviceObjects = new HashSet<>(); + ensureCSID(serviceType, NuxeoBasedResource.READ); + try { + ServiceContext ctx = createServiceContext(); + TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); + + List bindings = tReader.getServiceBindingsByType(ctx.getTenantId(), serviceType); + if (bindings == null || bindings.isEmpty()) { + // 404 if there are no mappings. + Response response = Response.status(Response.Status.NOT_FOUND) + .entity(ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(serviceType)) + .type("text/plain") + .build(); + throw new CSWebApplicationException(response); + } + + for (ServiceBindingType binding : bindings) { + ServiceObjectType serviceObj = binding.getObject(); + if (serviceObj != null) { + if (binding.getTags() != null) { + serviceObjects.addAll(binding.getTags().getTag()); + } + } + } + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceType); + } + + try { + CommonList commonList = new CommonList(); + commonList.setPageNum(0); + commonList.setPageSize(serviceObjects.size()); + commonList.setItemsInPage(serviceObjects.size()); + commonList.setTotalItems(serviceObjects.size()); + + String[] fields = new String[1]; + fields[0] = ServiceGroupListItemJAXBSchema.NAME; + commonList.setFieldsReturned(fields); + HashMap item = new HashMap(); + for (String service : serviceObjects) { + item.put(ServiceGroupListItemJAXBSchema.NAME, service); + commonList.addItem(item); + item.clear(); + } + return commonList; + } catch (ParserConfigurationException e) { + throw bigReThrow(e, ServiceMessages.UNKNOWN_ERROR_MSG, serviceType); + } + } + @GET @Path("{csid}/items") public AbstractCommonList getResourceItemList( - @Context UriInfo uriInfo, - @PathParam("csid") String serviceGroupName) { - UriInfoWrapper ui = new UriInfoWrapper(uriInfo); + @Context UriInfo uriInfo, @PathParam("csid") String serviceGroupName) { + UriInfoWrapper ui = new UriInfoWrapper(uriInfo); ensureCSID(serviceGroupName, NuxeoBasedResource.READ); AbstractCommonList list = null; try { ServiceContext ctx = createServiceContext(ui); - ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) - createDocumentHandler(ctx); - ArrayList groupsList = null; - if("common".equalsIgnoreCase(serviceGroupName)) { - groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); - } else { - groupsList = new ArrayList(); - groupsList.add(serviceGroupName); - } - - // check first for a csid query parameter + ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) createDocumentHandler(ctx); + ArrayList groupsList = null; + if ("common".equalsIgnoreCase(serviceGroupName)) { + groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); + } else { + groupsList = new ArrayList(); + groupsList.add(serviceGroupName); + } + + // check first for a csid query parameter MultivaluedMap queryParams = ctx.getQueryParams(); - String csid = queryParams.getFirst(IQueryManager.CSID_QUERY_PARAM); - if (csid != null && !csid.isEmpty()) { - String whereClause = QueryManager.createWhereClauseFromCsid(csid); - if (Tools.isEmpty(whereClause)) { - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is empty for csid: ["+csid+"]"); - } - } else { - DocumentFilter documentFilter = handler.getDocumentFilter(); - documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); - } - } - } else { - // check to see if we have to set up a keyword search - String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); - if (keywords != null && !keywords.isEmpty()) { - String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); - if(Tools.isEmpty(whereClause)) { - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]"); - } - } else { - DocumentFilter documentFilter = handler.getDocumentFilter(); - documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); - } - } - } - } - + String csid = queryParams.getFirst(IQueryManager.CSID_QUERY_PARAM); + if (csid != null && !csid.isEmpty()) { + String whereClause = QueryManager.createWhereClauseFromCsid(csid); + if (Tools.isEmpty(whereClause)) { + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is empty for csid: [" + csid + "]"); + } + } else { + DocumentFilter documentFilter = handler.getDocumentFilter(); + documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + } + } + } else { + // check to see if we have to set up a keyword search + String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); + if (keywords != null && !keywords.isEmpty()) { + String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); + if (Tools.isEmpty(whereClause)) { + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is empty for keywords: [" + keywords + "]"); + } + } else { + DocumentFilter documentFilter = handler.getDocumentFilter(); + documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + } + } + } + } + String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS); - if (advancedSearch != null && !advancedSearch.isEmpty()) { - DocumentFilter documentFilter = handler.getDocumentFilter(); - String whereClause = QueryManager.createWhereClauseFromAdvancedSearch(advancedSearch); - documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); - } - } - - // make the query + if (advancedSearch != null && !advancedSearch.isEmpty()) { + DocumentFilter documentFilter = handler.getDocumentFilter(); + String whereClause = QueryManager.createWhereClauseFromAdvancedSearch(advancedSearch); + documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + } + } + + // make the query list = handler.getItemListForGroup(ctx, groupsList); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName); @@ -282,30 +337,29 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl ctx = createServiceContext(ui); - ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) - createDocumentHandler(ctx); - ArrayList groupsList = null; - if("common".equalsIgnoreCase(serviceGroupName)) { - groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); - } else { - groupsList = new ArrayList(); - groupsList.add(serviceGroupName); - } - + ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler) createDocumentHandler(ctx); + ArrayList groupsList = null; + if ("common".equalsIgnoreCase(serviceGroupName)) { + groupsList = ServiceBindingUtils.getCommonServiceTypes(INCLUDE_AUTHORITIES); + } else { + groupsList = new ArrayList(); + groupsList.add(serviceGroupName); + } + String whereClause = QueryManager.createWhereClauseFromCsid(specifier); DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - + handler.setDocumentFilter(myFilter); + result = handler.getResourceItemForCsid(ctx, groupsList, specifier); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName); diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index e0bf42c97..77171ac0c 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -268,6 +268,10 @@ public class ServiceGroupDocumentModelHandler * @return true if the ServiceBinding contains all query parameters, false otherwise */ public boolean acceptServiceBinding(ServiceBindingType binding, String queryTag) { + if (queryTag == null || queryTag.isEmpty()) { + return true; + } + final Tags tags = binding.getTags(); final List tagList = tags == null ? Collections.emptyList() : tags.getTag();