import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
+
import org.collectionspace.authentication.CSpaceTenant;
import org.collectionspace.services.authorization.AuthZ;
-import org.collectionspace.services.client.PersonAuthorityClient;
-import org.collectionspace.services.client.PersonAuthorityClientUtils;
-import org.collectionspace.services.client.PoxPayloadOut;
-import org.collectionspace.services.person.PersonAuthorityResource;
+import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.vocabulary.AuthorityResource;
import org.collectionspace.services.config.service.AuthorityInstanceType;
import org.collectionspace.services.config.service.ServiceBindingType;
import org.collectionspace.services.config.service.ServiceBindingType.AuthorityInstanceList;
+import org.collectionspace.services.config.service.Term;
+import org.collectionspace.services.config.service.TermList;
import org.collectionspace.services.config.tenant.TenantBindingType;
+import java.lang.reflect.Constructor;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
+import java.util.logging.Level;
public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
+ java.util.logging.Logger logger = java.util.logging.Logger.getAnonymousLogger();
+
@Override
public void contextInitialized(ServletContextEvent event) {
try {
// This call to super instantiates and initializes our JAX-RS application class.
// The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication.
//
- System.out.println(String.format("%tc [INFO] Starting up the CollectionSpace Services' JAX-RS application.", new Date()));
+ logger.log(Level.INFO, String.format("%tc [INFO] Starting up the CollectionSpace Services' JAX-RS application.", new Date()));
super.contextInitialized(event);
CollectionSpaceJaxRsApplication app = (CollectionSpaceJaxRsApplication)deployment.getApplication();
Dispatcher disp = deployment.getDispatcher();
initializeAuthorities(app.getResourceMap());
- System.out.println(String.format("%tc [INFO] CollectionSpace Services' JAX-RS application started.", new Date()));
- } catch (Throwable e) {
+ logger.log(Level.INFO, String.format("%tc [INFO] CollectionSpace Services' JAX-RS application started.", new Date()));
+ } catch (Exception e) {
e.printStackTrace();
- throw e;
+ throw new RuntimeException(e);
}
}
@Override
public void contextDestroyed(ServletContextEvent event) {
- System.out.println("[INFO] Shutting down the CollectionSpace Services' JAX-RS application.");
+ logger.log(Level.INFO, "[INFO] Shutting down the CollectionSpace Services' JAX-RS application.");
//Do something if needed.
- System.out.println("[INFO] CollectionSpace Services' JAX-RS application stopped.");
+ logger.log(Level.INFO, "[INFO] CollectionSpace Services' JAX-RS application stopped.");
}
- public void initializeAuthorities(ResourceMap resourceMap) {
+ /**
+ * Initialize all authorities and vocabularies defined in the service bindings.
+ * @param resourceMap
+ * @throws Exception
+ */
+ public void initializeAuthorities(ResourceMap resourceMap) throws Exception {
TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
Hashtable<String, TenantBindingType> tenantBindingsTable = tenantBindingConfigReader.getTenantBindings(false);
for (TenantBindingType tenantBindings : tenantBindingsTable.values()) {
+ CSpaceTenant tenant = new CSpaceTenant(tenantBindings.getId(), tenantBindings.getName());
for (ServiceBindingType serviceBinding : tenantBindings.getServiceBindings()) {
AuthorityInstanceList element = serviceBinding.getAuthorityInstanceList();
if (element != null && element.getAuthorityInstance() != null) {
List<AuthorityInstanceType> authorityInstanceList = element.getAuthorityInstance();
for (AuthorityInstanceType authorityInstance : authorityInstanceList) {
- CSpaceTenant tenant = new CSpaceTenant(tenantBindings.getId(), tenantBindings.getName());
- initializeAuthorityInstance(resourceMap, authorityInstance, serviceBinding.getName(), tenant);
+ try {
+ initializeAuthorityInstance(resourceMap, authorityInstance, serviceBinding, tenant);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Could not initialize authorities and authority terms: " + e.getMessage());
+ throw e;
+ }
}
}
}
}
}
+
+ @SuppressWarnings("rawtypes")
+ private AuthorityClient getAuthorityClient(String classname) throws Exception {
+ Class clazz = Class.forName(classname.trim());
+ Constructor co = clazz.getConstructor(null);
+ Object classInstance = co.newInstance(null);
+ return (AuthorityClient) classInstance;
+ }
+
+ /*
+ * Check to see if an an authority instance and its corresponding terms exist. If not, try to create them.
+ */
+ private void initializeAuthorityInstance(ResourceMap resourceMap, AuthorityInstanceType authorityInstance, ServiceBindingType serviceBinding, CSpaceTenant tenant) throws Exception {
+ int status = -1;
+ Response response = null;
+ String serviceName = serviceBinding.getName();
+
+ AuthZ.get().login(tenant);
+ String clientClassName = serviceBinding.getClientHandler();
+ AuthorityClient client = getAuthorityClient(clientClassName);
+ String authoritySpecifier = RefName.shortIdToPath(authorityInstance.getTitleRef()); // e.g., urn:cspace:name(ulan)
- private void initializeAuthorityInstance(ResourceMap resourceMap, AuthorityInstanceType authorityInstance, String serviceName, CSpaceTenant tenant) {
- // TODO Auto-generated method stub
+ //
+ // Test to see if the authority instance exists already.
+ //
+ AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(serviceName.toLowerCase());
try {
- AuthZ.get().login(tenant);
- PersonAuthorityClient client = new PersonAuthorityClient();
- PoxPayloadOut xmlPayloadOut = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- authorityInstance.getTitle(), authorityInstance.getTitleRef(), client.getCommonPartName());
- String xmlPayload = xmlPayloadOut.asXML();
- PersonAuthorityResource personAuthorityResource = (PersonAuthorityResource) resourceMap.get(serviceName.toLowerCase());
- Response response = personAuthorityResource.createAuthority(xmlPayload);
- int status = response.getStatus();
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ response = authorityResource.get(null, null, authoritySpecifier);
+ } catch (CSWebApplicationException e) {
+ response = e.getResponse(); // If the authority doesn't exist, we expect a 404 error
}
- }
-
- private void initializeVocabularies() {
- // TODO Auto-generated method stub
+ //
+ // If it doesn't exist (status is not 200), then try to create the authority instance
+ //
+ status = response.getStatus();
+ if (status != Response.Status.OK.getStatusCode()) {
+ String xmlPayload = client.createAuthorityInstance(authorityInstance.getTitleRef(), authorityInstance.getTitle());
+ response = authorityResource.createAuthority(xmlPayload);
+ status = response.getStatus();
+ if (status != Response.Status.CREATED.getStatusCode()) {
+ throw new CSWebApplicationException(response);
+ }
+ }
+
+ if (status == Response.Status.OK.getStatusCode()) {
+ logger.log(Level.FINE, String.format("Authority of type '%s' with the short ID of '%s' existed already.",
+ serviceName, authorityInstance.getTitleRef()));
+ } else if (status == Response.Status.CREATED.getStatusCode()) {
+ logger.log(Level.INFO, String.format("Created a new authority of type '%s' with the short ID of '%s'.",
+ serviceName, authorityInstance.getTitleRef()));
+ } else {
+ logger.log(Level.WARNING, String.format("Unknown status '%d' encountered when creating or fetching authority of type '%s' with the short ID of '%s'.",
+ serviceName, authorityInstance.getTitleRef()));
+ }
+
+ //
+ // Finally, try to create or verify the authority terms.
+ //
+ initializeAuthorityInstanceTerms(authorityResource, client, authoritySpecifier, resourceMap, authorityInstance, serviceName, tenant);
}
+
+ private void initializeAuthorityInstanceTerms(
+ AuthorityResource authorityResource,
+ AuthorityClient client,
+ String authoritySpecifier,
+ ResourceMap resourceMap,
+ AuthorityInstanceType authorityInstance,
+ String serviceName,
+ CSpaceTenant tenant) throws Exception {
+
+ int status = -1;
+ Response response = null;
+ TermList termListElement = authorityInstance.getTermList();
+ for (Term term : termListElement.getTerm()) {
+ //
+ // Check to see if the term already exists
+ //
+ try {
+ String termSpecifier = RefName.shortIdToPath(term.getId());
+ authorityResource.getAuthorityItem(null, null, resourceMap, authoritySpecifier, termSpecifier);
+ status = Response.Status.OK.getStatusCode();
+ } catch (CSWebApplicationException e) {
+ response = e.getResponse(); // If the authority doesn't exist, we expect a 404 error
+ status = response.getStatus();
+ }
+
+ //
+ // If the term doesn't exist, create it.
+ //
+ if (status != Response.Status.OK.getStatusCode()) {
+ String termShortId = term.getId();
+ String termDisplayName = term.getContent().trim();
+ String xmlPayload = client.createAuthorityItemInstance(termShortId, termDisplayName);
+ try {
+ authorityResource.createAuthorityItem(resourceMap, null, authoritySpecifier, xmlPayload);
+ logger.log(Level.INFO, String.format("Created a new term '%s:%s' in the authority of type '%s' with the short ID of '%s'.",
+ termDisplayName, termShortId, serviceName, authorityInstance.getTitleRef()));
+ } catch (CSWebApplicationException e) {
+ response = e.getResponse();
+ status = response.getStatus();
+ if (status != Response.Status.CREATED.getStatusCode()) {
+ throw new CSWebApplicationException(response);
+ }
+ }
+ }
+ }
+ }
}
@Path("{csid}/items")
public Response createAuthorityItem(
@Context ResourceMap resourceMap,
- @Context UriInfo uriInfo,
+ @Context UriInfo uriInfo,
@PathParam("csid") String parentIdentifier, // Either a CSID or a URN form -e.g., a8ad38ec-1d7d-4bf2-bd31 or urn:cspace:name(bugsbunny)
String xmlPayload) {
uriInfo = new UriInfoWrapper(uriInfo);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
}
-
+
return result;
}
public void setInAuthority(CitationsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadOut = CitationAuthorityClientUtils.createCitationAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadOut.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public Response readItemWorkflow(String vcsid, String csid);
public Response updateItemWorkflowWithTransition(String vcsid, String csid, String workflowTransition);
+
+ //
+ // General utils
+ //
+
+ /*
+ * Should return a valid XML payload for creating an authority instance
+ */
+ public String createAuthorityInstance(String shortIdentifier, String displayName);
+
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName);
+
}
return null;
}
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
import org.w3c.dom.Document;
import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
+import org.collectionspace.services.client.CollectionSpaceClientUtils;
import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
* @return the string
*/
static protected String extractId(Response res) {
- MultivaluedMap<String, Object> mvm = res.getMetadata();
- String uri = (String) ((List<Object>) mvm.get("Location")).get(0);
- if (logger.isDebugEnabled()) {
- logger.debug("extractId:uri=" + uri);
- }
- String[] segments = uri.split("/");
- String id = segments[segments.length - 1];
- if (logger.isDebugEnabled()) {
- logger.debug("id=" + id);
- }
- return id;
+ return CollectionSpaceClientUtils.extractId(res);
}
}
String currentUser = ctx.getUserId();
- if (currentUser.equalsIgnoreCase(AuthN.ANONYMOUS_USER) == false) {
+ if (currentUser.equalsIgnoreCase(AuthN.ANONYMOUS_USER) == false &&
+ currentUser.equalsIgnoreCase(AuthN.SPRING_ADMIN_USER) == false) {
addAccountPermissionsPart();
}
}
public void setInAuthority(ConceptsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = ConceptAuthorityClientUtils.createConceptAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
import javax.ws.rs.core.Response;
import org.apache.commons.io.FileUtils;
+
import org.collectionspace.services.client.test.ServiceRequestType;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.concept.ConceptTermGroup;
import org.collectionspace.services.concept.ConceptauthoritiesCommon;
+
import org.dom4j.DocumentException;
-import org.jboss.resteasy.client.ClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
<xs:element name="web-url" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
<xs:element name="title-ref" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
-<!-- <xs:element ref="termList"/> -->
+ <xs:element ref="termList"/>
</xs:sequence>
</xs:complexType>
-<!--
<xs:element name="termList">
<xs:complexType>
<xs:sequence>
<xs:attribute name="id" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
--->
<!--
ServiceObjectType defines the manifest for a collectionspace
public void setInAuthority(LocationsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = LocationAuthorityClientUtils.createLocationAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
*/
public class MaterialAuthorityClient extends AuthorityClientImpl<MaterialauthoritiesCommon, MaterialsCommon, MaterialAuthorityProxy> {
+ public static final String SERVICE_BINDING_NAME = "MaterialAuthority";
public static final String SERVICE_NAME = "materialauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
public void setInAuthority(MaterialsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadOut = MaterialAuthorityClientUtils.createMaterialAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadOut.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
materialAuthority.setShortIdentifier(shortIdentifier);
String refName = createMaterialAuthRefName(shortIdentifier, displayName);
materialAuthority.setRefName(refName);
- materialAuthority.setVocabType("MaterialAuthority"); //FIXME: REM - Should this really be hard-coded?
+ materialAuthority.setVocabType(MaterialAuthorityClient.SERVICE_BINDING_NAME);
PoxPayloadOut multipart = new PoxPayloadOut(MaterialAuthorityClient.SERVICE_PAYLOAD_NAME);
PayloadOutputPart commonPart = multipart.addPart(materialAuthority, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(headerLabel);
public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = OrgAuthorityClientUtils.createOrgAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public void setInAuthority(PersonsCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ //
+ // Should return a valid XML payload for creating an authority instance
+ //
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return personAuthorityInstance.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut personAuthorityInstance = PersonAuthorityClientUtils.createPersonInstance(shortIdentifier, displayName, SERVICE_COMMON_PART_NAME);
+ return personAuthorityInstance.asXML();
+ }
}
res.close();
}
}
-
+
/**
* Creates the person authority instance.
*
return multipart;
}
+ /*
+ * Create a very simple Person term -just a short ID and display name.
+ */
+ public static PoxPayloadOut createPersonInstance(String shortIdentifier, String displayName,
+ String headerLabel) {
+ List<PersonTermGroup> terms = getTermGroupInstance(shortIdentifier, displayName);
+
+ Map<String, String> personInfo = new HashMap<String, String>();
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortIdentifier);
+
+ return createPersonInstance(null, null, personInfo, terms, null, headerLabel);
+ }
+
/**
* Creates a person instance.
*
* @param headerLabel the header label
* @return the multipart output
*/
- public static PoxPayloadOut createPersonInstance(String inAuthority,
+ public static PoxPayloadOut createPersonInstance(
+ String inAuthority,
String personAuthRefName,
Map<String, String> personInfo,
List<PersonTermGroup> terms,
- String headerLabel){
+ String headerLabel) {
if (terms == null || terms.isEmpty()) {
terms = getTermGroupInstance(getGeneratedIdentifier());
}
- final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO =
- new HashMap<String, List<String>>();
+ final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO = new HashMap<String, List<String>>();
return createPersonInstance(inAuthority, null /*personAuthRefName*/,
personInfo, terms, EMPTY_PERSON_REPEATABLES_INFO, headerLabel);
}
* @param headerLabel the header label
* @return the multipart output
*/
- public static PoxPayloadOut createPersonInstance(String inAuthority,
+ public static PoxPayloadOut createPersonInstance(
+ String inAuthority,
String personAuthRefName,
Map<String, String> personInfo,
List<PersonTermGroup> terms,
Map<String, List<String>> personRepeatablesInfo,
- String headerLabel){
+ String headerLabel) {
+
PersonsCommon person = new PersonsCommon();
person.setInAuthority(inAuthority);
String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER);
}
person.setShortIdentifier(shortId);
- String value;
- List<String> values = null;
+ if (personInfo != null) {
+ String value;
- if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_DATE))!=null) {
- StructuredDateGroup birthDate = new StructuredDateGroup();
- birthDate.setDateDisplayDate(value);
- person.setBirthDateGroup(birthDate);
- }
- if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_DATE))!=null) {
- StructuredDateGroup deathDate = new StructuredDateGroup();
- deathDate.setDateDisplayDate(value);
- person.setDeathDateGroup(deathDate);
+ if ((value = personInfo.get(PersonJAXBSchema.BIRTH_DATE)) != null) {
+ StructuredDateGroup birthDate = new StructuredDateGroup();
+ birthDate.setDateDisplayDate(value);
+ person.setBirthDateGroup(birthDate);
+ }
+ if ((value = personInfo.get(PersonJAXBSchema.DEATH_DATE)) != null) {
+ StructuredDateGroup deathDate = new StructuredDateGroup();
+ deathDate.setDateDisplayDate(value);
+ person.setDeathDateGroup(deathDate);
+ }
+ if ((value = personInfo.get(PersonJAXBSchema.BIRTH_PLACE)) != null)
+ person.setBirthPlace(value);
+ if ((value = personInfo.get(PersonJAXBSchema.DEATH_PLACE)) != null)
+ person.setDeathPlace(value);
+ if ((value = personInfo.get(PersonJAXBSchema.GENDER)) != null)
+ person.setGender(value);
+ if ((value = personInfo.get(PersonJAXBSchema.BIO_NOTE)) != null)
+ person.setBioNote(value);
+ if ((value = personInfo.get(PersonJAXBSchema.NAME_NOTE)) != null)
+ person.setNameNote(value);
}
- if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_PLACE))!=null)
- person.setBirthPlace(value);
- if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)
- person.setDeathPlace(value);
- if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)
- person.setGender(value);
- if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)
- person.setBioNote(value);
- if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)
- person.setNameNote(value);
// Set values in the Term Information Group
PersonTermGroupList termList = new PersonTermGroupList();
termList.getPersonTermGroup().addAll(terms);
person.setPersonTermGroupList(termList);
- if (personRepeatablesInfo != null) {
- if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) {
- GroupList groupsList = new GroupList();
- List<String> groups = groupsList.getGroup();
- groups.addAll(values);
- person.setGroups(groupsList);
- }
- if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES))!=null) {
- NationalityList nationalitiesList = new NationalityList();
- List<String> nationalities = nationalitiesList.getNationality();
- nationalities.addAll(values);
- person.setNationalities(nationalitiesList);
- }
+ if (personRepeatablesInfo != null) {
+ List<String> values = null;
- if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS))!=null) {
- OccupationList occupationsList = new OccupationList();
- List<String> occupations = occupationsList.getOccupation();
- occupations.addAll(values);
- person.setOccupations(occupationsList);
- }
- if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES))!=null) {
- SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();
- List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();
- schoolsOrStyles.addAll(values);
- person.setSchoolsOrStyles(schoolOrStyleList);
- }
- }
+ if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.GROUPS)) != null) {
+ GroupList groupsList = new GroupList();
+ List<String> groups = groupsList.getGroup();
+ groups.addAll(values);
+ person.setGroups(groupsList);
+ }
+ if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES)) != null) {
+ NationalityList nationalitiesList = new NationalityList();
+ List<String> nationalities = nationalitiesList.getNationality();
+ nationalities.addAll(values);
+ person.setNationalities(nationalitiesList);
+ }
+
+ if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS)) != null) {
+ OccupationList occupationsList = new OccupationList();
+ List<String> occupations = occupationsList.getOccupation();
+ occupations.addAll(values);
+ person.setOccupations(occupationsList);
+ }
+ if ((values = (List<String>) personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES)) != null) {
+ SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();
+ List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();
+ schoolsOrStyles.addAll(values);
+ person.setSchoolsOrStyles(schoolOrStyleList);
+ }
+ }
-
PoxPayloadOut multipart = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- PayloadOutputPart commonPart = multipart.addPart(person,
- MediaType.APPLICATION_XML_TYPE);
+ PayloadOutputPart commonPart = multipart.addPart(person, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(headerLabel);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("to be created, person common ", person, PersonsCommon.class);
}
return newStr.toString();
}
- public static List<PersonTermGroup> getTermGroupInstance(String identifier) {
- if (Tools.isBlank(identifier)) {
- identifier = getGeneratedIdentifier();
+ private static List<PersonTermGroup> getTermGroupInstance(String shortIdentifier) {
+ return getTermGroupInstance(shortIdentifier, shortIdentifier);
+ }
+
+ public static List<PersonTermGroup> getTermGroupInstance(String shortIdentifier, String displayName) {
+ if (Tools.isBlank(shortIdentifier)) {
+ shortIdentifier = getGeneratedIdentifier();
+ }
+ if (Tools.isBlank(shortIdentifier)) {
+ displayName = shortIdentifier;
}
+
List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
PersonTermGroup term = new PersonTermGroup();
- term.setTermDisplayName(identifier);
- term.setTermName(identifier);
+ term.setTermDisplayName(displayName);
+ term.setTermName(shortIdentifier);
terms.add(term);
return terms;
}
private static String createIdentifier() {
long identifier = System.currentTimeMillis() + random.nextInt();
return Long.toString(identifier);
- }
-
+ }
}
public void setInAuthority(PlacesCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = PlaceAuthorityClientUtils.createPlaceAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public void setInAuthority(TaxonCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public String getInAuthority(VocabularyitemsCommon item) {
return item.getInAuthority();
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = VocabularyClientUtils.createVocabularyInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = VocabularyClientUtils.createVocabularyItemInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
}
import org.collectionspace.services.client.test.ServiceRequestType;
import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
import org.collectionspace.services.vocabulary.VocabulariesCommon;
-import org.jboss.resteasy.client.ClientResponse;
-//import org.jboss.resteasy.plugins.providers.multipart.PoxPayloadOut;
-//import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger =
LoggerFactory.getLogger(VocabularyClientUtils.class);
- public static PoxPayloadOut createEnumerationInstance(
+ public static PoxPayloadOut createVocabularyInstance(
String displayName, String shortIdentifier, String headerLabel ) {
VocabulariesCommon vocabulary = new VocabulariesCommon();
vocabulary.setDisplayName(displayName);
return multipart;
}
- // Note that we do not use the map, but we will once we add more info to the
- // items
public static PoxPayloadOut createVocabularyItemInstance(
String vocabularyRefName, Map<String, String> vocabItemInfo, String headerLabel){
- VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
String shortId = vocabItemInfo.get(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
String displayName = vocabItemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME);
- vocabularyItem.setShortIdentifier(shortId);
+ return createVocabularyItemInstance(displayName, shortId, headerLabel);
+ }
+
+ public static PoxPayloadOut createVocabularyItemInstance(
+ String displayName, String shortIdentifier, String headerLabel ){
+ VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
+ vocabularyItem.setShortIdentifier(shortIdentifier);
vocabularyItem.setDisplayName(displayName);
//String refName = createVocabularyItemRefName(vocabularyRefName, shortId, displayName);
//vocabularyItem.setRefName(refName);
}
return multipart;
- }
+ }
public static String createItemInVocabulary(String vcsid,
String vocabularyRefName, Map<String,String> itemMap,
// Submit the request to the service and store the response.
VocabularyClient client = new VocabularyClient();
- PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
+ PoxPayloadOut multipart = VocabularyClientUtils.createVocabularyInstance(
"Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
Response res = client.create(multipart);
try {
// Create a new vocabulary
String shortId = "nonunique" + random.nextInt(1000); // Prevent collisions with past test sessions that never cleaned up properly
VocabularyClient client = new VocabularyClient();
- PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
+ PoxPayloadOut multipart = VocabularyClientUtils.createVocabularyInstance(
"Vocab with non-unique Short Id", shortId, client.getCommonPartName());
Response res = client.create(multipart);
try {
protected PoxPayloadOut createInstance(String commonPartName,
String identifier) {
String displayName = "displayName-" + identifier;
- PoxPayloadOut result = VocabularyClientUtils.createEnumerationInstance(
+ PoxPayloadOut result = VocabularyClientUtils.createVocabularyInstance(
displayName, identifier, commonPartName);
return result;
}
public void setInAuthority(WorksCommon item, String inAuthorityCsid) {
item.setInAuthority(inAuthorityCsid);
}
+
+ @Override
+ public String createAuthorityInstance(String shortIdentifier, String displayName) {
+ PoxPayloadOut poxPayloadout = WorkAuthorityClientUtils.createWorkAuthorityInstance(displayName, shortIdentifier, SERVICE_COMMON_PART_NAME);
+ return poxPayloadout.asXML();
+ }
+
+ @Override
+ public String createAuthorityItemInstance(String shortIdentifier, String displayName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}