From a5cf667d98a88ed97f99911886db90b5e9c99831 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 21 May 2010 23:11:22 +0000 Subject: [PATCH] CSPACE-1880: Partial matches in authorities causing sql errors --- .../organization/OrgAuthorityResource.java | 7 +++--- .../client/PersonAuthorityClient.java | 2 +- .../client/PersonAuthorityClientUtils.java | 9 ++++--- .../test/PersonAuthorityServiceTest.java | 16 +++++++++--- .../person/PersonAuthorityResource.java | 25 ++++++------------- .../client/test/VocabularyServiceTest.java | 5 ++-- .../vocabulary/VocabularyResource.java | 10 +------- 7 files changed, 32 insertions(+), 42 deletions(-) diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index a33800ad7..fce0ab972 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -752,7 +752,7 @@ public class OrgAuthorityResource extends // AND organizations_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON + + String ptClause = OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + OrganizationJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); @@ -811,9 +811,8 @@ public class OrgAuthorityResource extends // AND organizations_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = "AND " + - OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + - OrganizationJAXBSchema.DISPLAY_NAME + + String ptClause = OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + + OrganizationJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java index 2f8f0348d..b89410b23 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java @@ -95,7 +95,7 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { */ public void setProxy() { if (useAuth()) { - personAuthorityProxy = ProxyFactory.create(PersonAuthorityProxy.class, + personAuthorityProxy = ProxyFactory.create(PersonAuthorityProxy.class, //FIXME: This method is deprecated. We need to use the new "executor" model -see related JavaDocs. getBaseURL(), getHttpClient()); } else { personAuthorityProxy = ProxyFactory.create(PersonAuthorityProxy.class, diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index f8053164c..142aa80fe 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -114,7 +114,7 @@ public class PersonAuthorityClientUtils { } String value; - if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) + if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) //FIXME: REM - I don't think we need to check for null -null is a valid value and won't cause any problems. person.setForeName(value); if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null) person.setMiddleName(value); @@ -150,6 +150,7 @@ public class PersonAuthorityClientUtils { person.setBioNote(value); if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null) person.setNameNote(value); + MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(person, MediaType.APPLICATION_XML_TYPE); @@ -199,12 +200,12 @@ public class PersonAuthorityClientUtils { String refName = createPersonRefName(personAuthorityRefName, displayName, true); if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+displayName + logger.debug("Import: Create Item: \"" + displayName +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\""); } MultipartOutput multipart = - createPersonInstance( vcsid, refName, - personMap, client.getItemCommonPartName() ); + createPersonInstance(vcsid, refName, + personMap, client.getItemCommonPartName()); String result = null; ClientResponse res = client.createItem(vcsid, multipart); diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 22fd54ccd..30fb54f8c 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -283,7 +283,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { if (knownItemResourceId == null){ knownItemResourceId = newID; if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } } @@ -1557,6 +1557,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); + + if (logger.isDebugEnabled() == true) { + logger.debug("About to update the following person..."); + logger.debug(objectAsXmlString(person, PersonsCommon.class)); + } // Update the contents of this resource. person.setCsid(null); @@ -1565,8 +1570,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { logger.debug("to be updated Person"); logger.debug(objectAsXmlString(person, PersonsCommon.class)); - } - + } + // Submit the updated resource to the service and store the response. MultipartOutput output = new MultipartOutput(); OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); @@ -1593,6 +1598,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(updatedPerson); + + if (logger.isDebugEnabled() == true) { + logger.debug("Updated to following person to:"); + logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class)); + } // Verify that the updated resource received the correct data. Assert.assertEquals(updatedPerson.getForeName(), diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 7815fe6b1..9a1d08afb 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -304,7 +304,7 @@ public class PersonAuthorityResource extends */ @GET @Path("{csid}/items/{itemcsid}/refObjs") - @Produces("application/xml") //FIXME: REM do this for CSPACE-1079 in Org authority. + @Produces("application/xml") public AuthorityRefDocList getReferencingObjects( @PathParam("csid") String parentcsid, @PathParam("itemcsid") String itemcsid, @@ -554,7 +554,6 @@ public class PersonAuthorityResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); throw new WebApplicationException(response); } - } /** @@ -686,14 +685,11 @@ public class PersonAuthorityResource extends // AND persons_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = - PersonJAXBSchema.PERSONS_COMMON + ":" + + String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - // handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - + handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); } getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); @@ -731,9 +727,8 @@ public class PersonAuthorityResource extends @Context UriInfo ui) { PersonsCommonList personObjectList = new PersonsCommonList(); try { - String whereClause = - PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+ - ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME+ + String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON + + ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME + "='" + parentSpecifier+"'"; // Need to get an Authority by name MultivaluedMap queryParams = ui.getQueryParameters(); @@ -749,14 +744,11 @@ public class PersonAuthorityResource extends // AND persons_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = "AND " + - PersonJAXBSchema.PERSONS_COMMON + ":" + + String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - // handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - handler.getDocumentFilter().appendWhereClause(ptClause, ""); - + handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); } getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); @@ -891,7 +883,6 @@ public class PersonAuthorityResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); throw new WebApplicationException(response); } - } /** @@ -938,7 +929,6 @@ public class PersonAuthorityResource extends .type("text/plain").build(); throw new WebApplicationException(response); } - } /** @@ -1185,5 +1175,4 @@ public class PersonAuthorityResource extends throw new WebApplicationException(response); } } - } diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index 02c2f3225..73b7af6a9 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -1053,13 +1053,12 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { vocabularyItemResourceId = entry.getKey(); vocabularyResourceId = entry.getValue(); // Note: Any non-success responses are ignored and not reported. - ClientResponse res = - client.deleteItem(vocabularyResourceId, vocabularyItemResourceId); + client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection(); } // Clean up vocabulary resources. for (String resourceId : allResourceIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); + client.delete(resourceId).releaseConnection(); } } diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index a84d06b20..1a99e2c0e 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -494,10 +494,7 @@ public class VocabularyResource extends ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); -// DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); -// myFilter.setPagination(queryParams); - // "vocabularyitems_common:inVocabulary='" + parentcsid + "'"); + DocumentFilter myFilter = handler.getDocumentFilter(); myFilter.setWhereClause( VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":" + VocabularyItemJAXBSchema.IN_VOCABULARY + "=" @@ -511,15 +508,11 @@ public class VocabularyResource extends + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); } - if (logger.isDebugEnabled()) { logger.debug("getVocabularyItemList filtered WHERE clause: " + myFilter.getWhereClause()); } - - handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); - vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { Response response = Response.status( @@ -652,6 +645,5 @@ public class VocabularyResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); throw new WebApplicationException(response); } - } } -- 2.47.3