Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Commit

Permalink
Fix for #387 Ingest metadata profile is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Natasa Bulatovic committed Jan 22, 2016
1 parent 41f8ad9 commit 06bc9ce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public IngestController(User user, CollectionImeji collection) {
public void ingest(File itemListXmlFile, File profileXmlFile) throws Exception {
if (profileXmlFile != null) {
IngestProfileController ipc = new IngestProfileController(user);
ipc.ingest(profileXmlFile, collection.getProfile());
ipc.ingest(profileXmlFile, collection);
}
if (itemListXmlFile != null) {
ProfileController pc = new ProfileController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.io.File;
import java.net.URI;
import java.util.Date;
import java.util.HashMap;

import de.mpg.imeji.logic.controller.CollectionController;
import de.mpg.imeji.logic.controller.ProfileController;
import de.mpg.imeji.logic.ingest.parser.ProfileParser;
import de.mpg.imeji.logic.util.IdentifierUtil;
import de.mpg.imeji.logic.vo.CollectionImeji;
import de.mpg.imeji.logic.vo.MetadataProfile;
import de.mpg.imeji.logic.vo.Statement;
import de.mpg.imeji.logic.vo.User;
Expand Down Expand Up @@ -36,23 +39,50 @@ public IngestProfileController(User user) {
* @param profileXmlFile
* @throws Exception
*/
public void ingest(File profileXmlFile, URI profile) throws Exception {
public void ingest(File profileXmlFile, CollectionImeji collection) throws Exception {
URI profile = collection.getProfile();
ProfileParser pp = new ProfileParser();
MetadataProfile mdp = pp.parse(profileXmlFile);
if (isCopyOfOther(mdp, profile)) {
changeStatementURI(mdp);
}
MetadataProfile original;
ProfileController pc = new ProfileController();
MetadataProfile original = pc.retrieve(profile, user);
if (profile != null ){
if (isCopyOfOther(mdp, profile)) {
changeStatementURI(mdp);
}
original = pc.retrieve(profile, user);
}
else
{
original = new MetadataProfile();
}

original.setStatements(mdp.getStatements());
// ingested profile can never be default profile
original.setDefault(false);
try {
pc.update(original, user);
if (profile != null ) {
pc.update(original, user);
pc.removeMetadataWithoutStatement(original);
}
else
{
if (mdp.getTitle()!= null && mdp.getTitle() != "" ) {
original.setTitle(mdp.getTitle());
}
else
{
original.setTitle("Metadata profile for "+collection.getMetadata().getTitle()+" (ingested at: "+new Date(System.currentTimeMillis())+" )");
}
original.setDescription(mdp.getDescription());
mdp = pc.create(original, user);
CollectionController cc = new CollectionController();
collection.setProfile(mdp.getId());
cc.update(collection, user);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
pc.removeMetadataWithoutStatement(original);

}

/**
Expand Down Expand Up @@ -99,6 +129,13 @@ private MetadataProfile changeParentId(MetadataProfile mdp, HashMap<URI, URI> id
* @return
*/
private boolean isCopyOfOther(MetadataProfile mdp, URI uri) {
return uri.compareTo(mdp.getId()) != 0;
if ( mdp == null || uri ==null) {
return false;
}
else
{
return uri.compareTo(mdp.getId()) != 0;
}

}
}
10 changes: 6 additions & 4 deletions src/main/java/de/mpg/imeji/logic/ingest/jaxb/JaxbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class JaxbUtil {
public static <T> T unmarshal(String xsdFilename, String xmlFilename, Class<T> clss)
throws JAXBException, SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = (xsdFilename == null || xsdFilename.trim().length() == 0) ? null
: schemaFactory.newSchema(getFileURLInClasspath(xsdFilename));
JAXBContext jaxbContext = JAXBContext.newInstance(clss.getPackage().getName());
Expand All @@ -41,7 +41,7 @@ public static <T> T unmarshal(JAXBContext jaxbContext, Schema schema, String xml

public static <T> T unmarshal(String xsdFilename, File xmlFile, Class<T> clss)
throws JAXBException, SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = (xsdFilename == null || xsdFilename.trim().length() == 0) ? null
: schemaFactory.newSchema(getFileURLInClasspath(xsdFilename));
JAXBContext jaxbContext = JAXBContext.newInstance(clss.getPackage().getName());
Expand All @@ -54,10 +54,12 @@ public static <T> T unmarshal(JAXBContext jaxbContext, Schema schema, File xmlFi
unmarshaller.setSchema(schema);
return clss.cast(unmarshaller.unmarshal(xmlFile));
}

//be "http://www.w3.org/2000/xmlns/".

public static void marshal(String xsdFilename, String xmlFilename, Object jaxbElement)
throws JAXBException, SAXException, FileNotFoundException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = (xsdFilename == null || xsdFilename.trim().length() == 0) ? null
: schemaFactory.newSchema(getFileURLInClasspath(xsdFilename));
JAXBContext jaxbContext =
Expand All @@ -76,7 +78,7 @@ public static void marshal(JAXBContext jaxbContext, Schema schema, String xmlFil

public static void marshal(String xsdFilename, File xmlFile, Object jaxbElement)
throws JAXBException, SAXException, FileNotFoundException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = (xsdFilename == null || xsdFilename.trim().length() == 0) ? null
: schemaFactory.newSchema(getFileURLInClasspath(xsdFilename));
JAXBContext jaxbContext =
Expand Down

0 comments on commit 06bc9ce

Please sign in to comment.