1 package org.collectionspace.hello.services;
3 import javax.ws.rs.Consumes;
4 import javax.ws.rs.GET;
5 import javax.ws.rs.POST;
6 import javax.ws.rs.Path;
7 import javax.ws.rs.PathParam;
8 import javax.ws.rs.Produces;
9 import javax.ws.rs.WebApplicationException;
10 import javax.ws.rs.core.Response;
12 import java.util.UUID;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.atomic.AtomicLong;
15 import javax.ws.rs.core.UriBuilder;
16 import javax.xml.bind.JAXBContext;
17 import javax.xml.bind.Marshaller;
19 import org.collectionspace.hello.DomainIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 @Path("/domainidentifiers")
24 @Consumes("application/xml")
25 @Produces("application/xml")
26 public class DomainIdentifierResource extends CollectionSpaceResource {
28 final Logger logger = LoggerFactory.getLogger(DomainIdentifierResource.class);
29 private Map<String, DomainIdentifier> idDB = new ConcurrentHashMap<String, DomainIdentifier>();
31 public DomainIdentifierResource() {
36 public Response createIdentifier(DomainIdentifier id) {
37 DomainIdentifier newId = id;
39 if (newId.getDsid() == null) {
40 newId.setDsid("org.collectionspace");
42 newId.setDsid(newId.getDsid() + "." + System.currentTimeMillis());
43 idDB.put(newId.getDsid(), newId);
45 verbose("createIdentifier: ", newId);
46 UriBuilder path = UriBuilder.fromResource(DomainIdentifierResource.class);
47 path.path("" + newId.getDsid());
48 Response response = Response.created(path.build()).build();
55 public DomainIdentifier getIdentifier(@PathParam("id") String id) {
56 DomainIdentifier result = idDB.get(id);
58 Response response = Response.status(Response.Status.NOT_FOUND).entity(
59 "The requested DomainIdentifier was not found.").type("text/plain").build();
60 throw new WebApplicationException(response);
62 verbose("getIdentifier: ", result);
67 private void verbose(String msg, DomainIdentifier id) {
69 System.out.println("DomainIdentifierResource: " + msg);
70 JAXBContext jc = JAXBContext.newInstance(DomainIdentifier.class);
71 Marshaller m = jc.createMarshaller();
72 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
74 m.marshal(id, System.out);
76 } catch (Exception e) {