Changeset 226
- Timestamp:
- 03/15/10 18:10:30 (14 years ago)
- Location:
- VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main
- Files:
-
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/VirtualCollectionRegistry.java
r223 r226 3 3 import java.security.Principal; 4 4 import java.util.Collections; 5 import java.util.HashSet;6 5 import java.util.List; 7 6 import java.util.Map; … … 15 14 16 15 import eu.clarin.cmdi.virtualcollectionregistry.model.Handle; 17 import eu.clarin.cmdi.virtualcollectionregistry.model.Resource;18 import eu.clarin.cmdi.virtualcollectionregistry.model.ResourceMetadata;19 16 import eu.clarin.cmdi.virtualcollectionregistry.model.User; 20 17 import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; … … 108 105 vc.setOwner(user); 109 106 vc.setPid(Handle.createPid()); 110 for (Resource resource : vc.getResources()) {111 if (resource instanceof ResourceMetadata) {112 ResourceMetadata md = (ResourceMetadata) resource;113 md.setPid(Handle.createPid());114 }115 }116 107 em.persist(vc); 117 108 em.getTransaction().commit(); … … 120 111 em.getTransaction().begin(); 121 112 em.persist(new Handle(vc.getPid(), Handle.Type.COLLECTION, vc.getId())); 122 for (Resource resource : vc.getResources()) {123 if (resource instanceof ResourceMetadata) {124 ResourceMetadata md = (ResourceMetadata) resource;125 em.persist(new Handle(md.getPid(), Handle.Type.METADATA,126 md.getId()));127 }128 }129 113 em.getTransaction().commit(); 130 114 return vc.getId(); … … 167 151 c.updateFrom(vc); 168 152 validator.validate(c); 169 170 HashSet<String> newPids = new HashSet<String>();171 for (Resource resource : c.getResources()) {172 if (resource instanceof ResourceMetadata) {173 ResourceMetadata md = (ResourceMetadata) resource;174 if (md.getPid() == null) {175 String pid = Handle.createPid();176 md.setPid(pid);177 newPids.add(pid);178 }179 }180 }181 em.getTransaction().commit();182 em.getTransaction().begin();183 for (Resource resource : c.getResources()) {184 if (resource instanceof ResourceMetadata) {185 ResourceMetadata md = (ResourceMetadata) resource;186 if (newPids.contains(md.getPid())) {187 em.persist(new Handle(md.getPid(),188 Handle.Type.METADATA, md.getId()));189 }190 }191 }192 153 em.getTransaction().commit(); 193 154 return vc.getId(); … … 260 221 "error while retrieving virtual collection", e); 261 222 } 262 }263 264 public ResourceMetadata retrieveMetadataResource(long id)265 throws VirtualCollectionRegistryException {266 if (id <= 0) {267 throw new IllegalArgumentException("id <= 0");268 }269 270 try {271 EntityManager em = datastore.getEntityManager();272 em.getTransaction().begin();273 ResourceMetadata md = em.find(ResourceMetadata.class, new Long(id));274 em.getTransaction().commit();275 if (md == null) {276 throw new VirtualCollectionMetadataNotFoundException(id);277 }278 return md;279 } catch (VirtualCollectionRegistryException e) {280 throw e;281 } catch (Exception e) {282 logger.log(Level.SEVERE,283 "error while retrieving metadata resource", e);284 throw new VirtualCollectionRegistryException(285 "error while retrieving metadata resource", e);286 }287 288 223 } 289 224 -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/model/ClarinVirtualCollection.java
r146 r226 12 12 import javax.xml.bind.annotation.XmlElementWrapper; 13 13 import javax.xml.bind.annotation.XmlElements; 14 import javax.xml.bind.annotation.XmlIDREF;15 14 import javax.xml.bind.annotation.XmlRootElement; 16 15 import javax.xml.bind.annotation.XmlType; … … 66 65 propOrder = { "type", "ref" }) 67 66 public static class Proxy { 68 private ClarinVirtualCollection cvc;69 67 private Resource resource; 70 68 … … 72 70 } 73 71 74 private Proxy(ClarinVirtualCollection cvc, Resource resource) { 75 this.cvc = cvc; 72 private Proxy(Resource resource) { 76 73 this.resource = resource; 77 74 } … … 89 86 @XmlElement(name = "ResourceRef") 90 87 public String getRef() { 91 if (resource instanceof ResourceMetadata) { 92 return cvc.createHandleURI( 93 ((ResourceMetadata) resource).getPid()).toString(); 94 } else { 95 return ((ResourceProxy) resource).getRef(); 96 } 88 return resource.getRef(); 97 89 } 98 90 } // inner class Proxy … … 104 96 private Resources(ClarinVirtualCollection cvc) { 105 97 for (Resource r : cvc.getVirtualCollection().getResources()) { 106 proxies.add(new Proxy( cvc,r));98 proxies.add(new Proxy(r)); 107 99 } 108 100 } … … 120 112 @XmlAccessorType(XmlAccessType.NONE) 121 113 @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:components:vc", 122 propOrder = { "name", "description", "creationDate", "visibility", "origin", "creator" , "copyOfResourceMetadata"})114 propOrder = { "name", "description", "creationDate", "visibility", "origin", "creator" }) 123 115 public static class VC { 124 @XmlAccessorType(XmlAccessType.NONE)125 public static class CopyOfResources {126 private List<Resource> copyRefs = new ArrayList<Resource>();127 128 private void init(VirtualCollection vc) {129 for (Resource resource : vc.getResources()) {130 if (resource instanceof ResourceMetadata) {131 copyRefs.add(resource);132 }133 }134 }135 136 @XmlIDREF137 @XmlAttribute(name = "ref")138 public List<Resource> getRefs() {139 return copyRefs;140 }141 142 public boolean isEmpty() {143 return copyRefs.isEmpty();144 }145 } // inner class CopyOfResources146 147 private CopyOfResources copyRefs = new CopyOfResources();148 116 private VirtualCollection vc; 149 117 150 118 private void init(VirtualCollection vc) { 151 119 this.vc = vc; 152 this.copyRefs.init(vc);153 120 } 154 121 … … 182 149 public Creator getCreator() { 183 150 return vc.getCreator(); 184 }185 186 187 @XmlElement(name = "CopyOfResourceMetadata")188 public CopyOfResources getCopyOfResourceMetadata() {189 return copyRefs.isEmpty() ? null : copyRefs;190 151 } 191 152 } -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/model/Resource.java
r146 r226 2 2 3 3 import javax.persistence.Column; 4 import javax.persistence.DiscriminatorColumn;5 import javax.persistence.DiscriminatorType;6 4 import javax.persistence.Entity; 5 import javax.persistence.EnumType; 6 import javax.persistence.Enumerated; 7 7 import javax.persistence.GeneratedValue; 8 8 import javax.persistence.GenerationType; 9 9 import javax.persistence.Id; 10 import javax.persistence.Inheritance;11 import javax.persistence.InheritanceType;12 10 import javax.persistence.Table; 13 11 import javax.xml.bind.annotation.XmlAccessType; 14 12 import javax.xml.bind.annotation.XmlAccessorType; 15 13 import javax.xml.bind.annotation.XmlAttribute; 14 import javax.xml.bind.annotation.XmlElement; 16 15 import javax.xml.bind.annotation.XmlID; 17 import javax.xml.bind.annotation.XmlSeeAlso; 16 import javax.xml.bind.annotation.XmlType; 17 18 import org.apache.commons.lang.builder.HashCodeBuilder; 18 19 19 20 @Entity 20 21 @Table(name = "resource") 21 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)22 @DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING, length=1)23 22 @XmlAccessorType(XmlAccessType.NONE) 24 @Xml SeeAlso({ ResourceProxy.class, ResourceMetadata.class})25 public abstractclass Resource {23 @XmlType(propOrder = { "type", "ref" }) 24 public class Resource { 26 25 @Id 27 26 @GeneratedValue(strategy = GenerationType.AUTO) 28 27 @Column(name = "id", nullable = false, updatable = false, insertable = true) 29 28 private long id = -1; 29 @Column(name = "type", nullable = false) 30 @Enumerated(EnumType.ORDINAL) 31 private ResourceType type; 32 @Column(name = "ref", nullable = false) 33 private String ref; 30 34 31 pr otectedResource() {35 private Resource() { 32 36 super(); 37 } 38 39 public Resource(ResourceType type, String ref) { 40 this(); 41 this.setType(type); 42 this.setRef(ref); 33 43 } 34 44 … … 42 52 return "r" + id; 43 53 } 44 45 public abstract ResourceType getType();46 54 47 public abstract String getRef(); 55 public void setType(ResourceType type) { 56 if (type == null) { 57 throw new NullPointerException("type == null"); 58 } 59 this.type = type; 60 } 48 61 49 abstract int getSignature(); 62 @XmlElement(name = "ResourceType") 63 public ResourceType getType() { 64 return type; 65 } 50 66 51 } // abstract class Resource 67 public void setRef(String ref) { 68 if (ref == null) { 69 throw new NullPointerException("ref == null"); 70 } 71 this.ref = ref; 72 } 73 74 @XmlElement(name = "ResourceRef") 75 public String getRef() { 76 return ref; 77 } 78 79 protected int getSignature() { 80 return new HashCodeBuilder(799, 51) 81 .append(type) 82 .append(ref) 83 .toHashCode(); 84 } 85 86 } // class Resource -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/model/VirtualCollection.java
r220 r226 84 84 @Column(name = "id") 85 85 @XmlAttribute(name = "id") 86 private long id ;86 private long id = -1; 87 87 @ManyToOne(cascade = { CascadeType.PERSIST, 88 88 CascadeType.REFRESH, … … 126 126 @OrderBy("id") 127 127 @XmlElementWrapper(name = "Resources") 128 @XmlElements({ @XmlElement(name = "ResourceProxy", 129 type = ResourceProxy.class), 130 @XmlElement(name = "ResourceMetadata", 131 type = ResourceMetadata.class) }) 128 @XmlElements({ @XmlElement(name = "Resource", 129 type = Resource.class) }) 132 130 private Set<Resource> resources = new LinkedHashSet<Resource>(); 133 131 @Column(name = "created", nullable = false, updatable = false) -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/rest/VirtualCollectionRegistryRestService.java
r218 r226 33 33 import eu.clarin.cmdi.virtualcollectionregistry.model.ClarinVirtualCollection; 34 34 import eu.clarin.cmdi.virtualcollectionregistry.model.Handle; 35 import eu.clarin.cmdi.virtualcollectionregistry.model.ResourceMetadata;36 35 import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; 37 36 import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollectionList; … … 219 218 }; 220 219 return Response.ok(writer).build(); 221 }222 223 @GET224 @Path("/clarin-metadata/{id}")225 @Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })226 public Response getClarinMetadata(@PathParam("id") long id)227 throws VirtualCollectionRegistryException {228 System.err.println("Metadata!");229 ResourceMetadata md = registry.retrieveMetadataResource(id);230 return Response.ok(md).build();231 220 } 232 221 -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/resources/META-INF/VirtualCollection.xsd
r188 r226 2 2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 3 3 4 <xs:element name="VirtualCollection" type="VirtualCollectionType"/>4 <xs:element name="VirtualCollection" type="VirtualCollectionType" /> 5 5 6 <xs:element name="VirtualCollections" type="VirtualCollectionsType"/>6 <xs:element name="VirtualCollections" type="VirtualCollectionsType" /> 7 7 8 9 10 <xs:element ref="VirtualCollection"/>11 12 <xs:attribute name="totalCount" type="xs:integer"/>13 <xs:attribute name="offset" type="xs:integer"/>14 15 16 17 <xs:enumeration value="full"></xs:enumeration>18 <xs:enumeration value="partial"></xs:enumeration>19 20 21 22 8 <xs:complexType name="VirtualCollectionsType"> 9 <xs:sequence maxOccurs="unbounded"> 10 <xs:element ref="VirtualCollection" /> 11 </xs:sequence> 12 <xs:attribute name="totalCount" type="xs:integer" /> 13 <xs:attribute name="offset" type="xs:integer" /> 14 <xs:attribute name="result"> 15 <xs:simpleType> 16 <xs:restriction base="xs:string"> 17 <xs:enumeration value="full" /> 18 <xs:enumeration value="partial" /> 19 </xs:restriction> 20 </xs:simpleType> 21 </xs:attribute> 22 </xs:complexType> 23 23 24 25 26 <xs:element name="Name" type="xs:string"/>27 <xs:element minOccurs="0" name="Description" type="xs:string"/>28 <xs:element minOccurs="0" name="CreationDate" type="xs:date"/>29 <xs:element minOccurs="0" name="Visibility" type="VisibilityType"/>30 <xs:element name="Type" type="TypeType"/>31 <xs:element minOccurs="0" name="Origin" type="xs:string"/>32 <xs:element minOccurs="0" name="Creator" type="CreatorType"/>33 <xs:element name="Resources" type="ResourcesType"/>34 35 <xs:attribute name="id" type="xs:long"/>36 <xs:attribute name="persistentId" type="xs:string"/>37 24 <xs:complexType name="VirtualCollectionType"> 25 <xs:sequence> 26 <xs:element name="Name" type="xs:string" /> 27 <xs:element minOccurs="0" name="Description" type="xs:string" /> 28 <xs:element minOccurs="0" name="CreationDate" type="xs:date" /> 29 <xs:element minOccurs="0" name="Visibility" type="VisibilityType" /> 30 <xs:element name="Type" type="TypeType" /> 31 <xs:element minOccurs="0" name="Origin" type="xs:string" /> 32 <xs:element minOccurs="0" name="Creator" type="CreatorType" /> 33 <xs:element name="Resources" type="ResourcesType" /> 34 </xs:sequence> 35 <xs:attribute name="id" type="xs:long" use="optional" /> 36 <xs:attribute name="persistentId" type="xs:string" use="optional" /> 37 </xs:complexType> 38 38 39 39 40 <xs:complexType name="ResourcesType"> 41 <xs:sequence maxOccurs="unbounded"> 42 <xs:choice> 43 <xs:element name="ResourceProxy" type="ResourceProxyType"/> 44 <xs:element name="ResourceMetadata" type="ResourceMetadataType"/> 45 </xs:choice> 46 </xs:sequence> 47 </xs:complexType> 40 <xs:complexType name="ResourcesType"> 41 <xs:sequence maxOccurs="unbounded"> 42 <xs:element name="Resource" type="ResourceType" /> 43 </xs:sequence> 44 </xs:complexType> 48 45 49 <xs:complexType name="ResourceProxyType">50 51 <xs:element name="ResourceType" type="ResourceTypeType"/>52 <xs:element name="ResourceRef" type="ResourceRefType"/>53 54 <xs:attribute name="id" type="xs:ID"/>55 46 <xs:complexType name="ResourceType"> 47 <xs:sequence> 48 <xs:element name="ResourceType" type="ResourceTypeType" /> 49 <xs:element name="ResourceRef" type="ResourceRefType" /> 50 </xs:sequence> 51 <xs:attribute name="id" type="xs:ID" use="required" /> 52 </xs:complexType> 56 53 57 <xs:complexType name="ResourceMetadataType"> 58 <xs:sequence> 59 <xs:element name="Name" type="xs:string"/> 60 <xs:element name="Description" type="xs:string" minOccurs="0"/> 61 <xs:element name="Creator" type="CreatorType" minOccurs="0"/> 62 <xs:element name="ResourceRef" type="ResourceRefType"/> 63 </xs:sequence> 64 <xs:attribute name="id" type="xs:ID"/> 65 </xs:complexType> 54 <xs:complexType name="CreatorType"> 55 <xs:sequence> 56 <xs:element name="Name" type="xs:string" /> 57 <xs:element minOccurs="0" name="Email" type="xs:string" /> 58 <xs:element minOccurs="0" name="Organisation" type="xs:string" /> 59 </xs:sequence> 60 <xs:attribute name="ref" type="xs:IDREF" /> 61 </xs:complexType> 66 62 67 <xs:complexType name="CreatorType"> 68 <xs:sequence> 69 <xs:element name="Name" type="xs:string"/> 70 <xs:element minOccurs="0" name="Email" type="xs:string"/> 71 <xs:element minOccurs="0" name="Organisation" type="xs:string"/> 72 </xs:sequence> 73 <xs:attribute name="ref" type="xs:IDREF"/> 74 </xs:complexType> 63 <xs:simpleType name="ResourceTypeType"> 64 <xs:restriction base="xs:string"> 65 <xs:enumeration value="Metadata" /> 66 <xs:enumeration value="Resource" /> 67 </xs:restriction> 68 </xs:simpleType> 75 69 76 <xs:simpleType name="ResourceTypeType"> 77 <xs:restriction base="xs:string"> 78 <xs:enumeration value="Metadata"/> 79 <xs:enumeration value="Resource"/> 80 </xs:restriction> 81 </xs:simpleType> 70 <xs:simpleType name="ResourceRefType"> 71 <xs:restriction base="xs:anyURI" /> 72 </xs:simpleType> 82 73 83 <xs:simpleType name="ResourceRefType"> 84 <xs:restriction base="xs:anyURI"/> 85 </xs:simpleType> 74 <xs:simpleType name="VisibilityType"> 75 <xs:restriction base="xs:string"> 76 <xs:enumeration value="advertised" /> 77 <xs:enumeration value="non-advertised" /> 78 </xs:restriction> 79 </xs:simpleType> 86 80 87 <xs:simpleType name="VisibilityType"> 88 <xs:restriction base="xs:string"> 89 <xs:enumeration value="advertised"/> 90 <xs:enumeration value="non-advertised"/> 91 </xs:restriction> 92 </xs:simpleType> 93 94 <xs:simpleType name="TypeType"> 95 <xs:restriction base="xs:string"> 96 <xs:enumeration value="extensional"/> 97 <xs:enumeration value="intensional"/> 98 </xs:restriction> 99 </xs:simpleType> 81 <xs:simpleType name="TypeType"> 82 <xs:restriction base="xs:string"> 83 <xs:enumeration value="extensional" /> 84 <xs:enumeration value="intensional" /> 85 </xs:restriction> 86 </xs:simpleType> 100 87 101 88 </xs:schema> -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/resources/META-INF/persistence.xml
r212 r226 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <persistence xmlns="http://java.sun.com/xml/ns/persistence" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 5 version="2.0"> 6 <persistence-unit name="VirtualCollectionStore" 7 transaction-type="RESOURCE_LOCAL"> 8 <provider>org.hibernate.ejb.HibernatePersistence</provider> 9 <jta-data-source>java:comp/env/jdbc/VirtualCollectionStore</jta-data-source> 10 <class>eu.clarin.cmdi.virtualcollectionregistry.model.User</class> 11 <class>eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection</class> 12 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Creator</class> 13 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Resource</class> 14 <class>eu.clarin.cmdi.virtualcollectionregistry.model.ResourceProxy</class> 15 <class>eu.clarin.cmdi.virtualcollectionregistry.model.ResourceMetadata</class> 16 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Handle</class> 17 <properties> 18 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 19 <property name="hibernate.max_fetch_depth" value="3" /> 20 <property name="hibernate.hbm2ddl.auto" value="update" /> 21 <property name="hibernate.show_sql" value="false" /> 22 <property name="hibernate.format_sql" value="false"/> 23 </properties> 24 </persistence-unit> 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 5 version="2.0"> 6 <persistence-unit name="VirtualCollectionStore" 7 transaction-type="RESOURCE_LOCAL"> 8 <provider>org.hibernate.ejb.HibernatePersistence</provider> 9 <jta-data-source>java:comp/env/jdbc/VirtualCollectionStore</jta-data-source> 10 <class>eu.clarin.cmdi.virtualcollectionregistry.model.User</class> 11 <class>eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection</class> 12 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Creator</class> 13 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Resource</class> 14 <class>eu.clarin.cmdi.virtualcollectionregistry.model.Handle</class> 15 <properties> 16 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 17 <property name="hibernate.max_fetch_depth" value="3" /> 18 <property name="hibernate.hbm2ddl.auto" value="update" /> 19 <property name="hibernate.show_sql" value="false" /> 20 <property name="hibernate.format_sql" value="false" /> 21 </properties> 22 </persistence-unit> 25 23 </persistence>
Note: See TracChangeset
for help on using the changeset viewer.