use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRLinkTableManager method create.
/**
* Creates all references for the given object. You should call {@link #delete(MCRObjectID)} before using this
* method otherwise doublets could occur.
*
* @param obj the object to create the references
*/
public void create(MCRObject obj) {
MCRObjectID mcrId = obj.getId();
// set new entries
MCRObjectMetadata meta = obj.getMetadata();
// use Set for category collection to remove duplicates if there are any
Collection<MCRCategoryID> categories = new HashSet<>();
meta.stream().flatMap(MCRMetaElement::stream).forEach(inf -> {
if (inf instanceof MCRMetaClassification) {
String classId = ((MCRMetaClassification) inf).getClassId();
String categId = ((MCRMetaClassification) inf).getCategId();
categories.add(new MCRCategoryID(classId, categId));
} else if (inf instanceof MCRMetaLinkID) {
addReferenceLink(mcrId.toString(), ((MCRMetaLink) inf).getXLinkHref(), MCRLinkTableManager.ENTRY_TYPE_REFERENCE, "");
} else if (inf instanceof MCRMetaDerivateLink) {
addReferenceLink(mcrId.toString(), ((MCRMetaLink) inf).getXLinkHref(), MCRLinkTableManager.ENTRY_TYPE_DERIVATE_LINK, "");
}
});
MCRCategoryID state = obj.getService().getState();
if (state != null) {
categories.add(state);
}
if (categories.size() > 0) {
MCRCategLinkReference objectReference = new MCRCategLinkReference(mcrId);
MCRCategLinkServiceFactory.getInstance().setLinks(objectReference, categories);
}
// add derivate reference
MCRObjectStructure structure = obj.getStructure();
for (int i = 0; i < structure.getDerivates().size(); i++) {
MCRMetaLinkID lid = structure.getDerivates().get(i);
addReferenceLink(obj.getId(), lid.getXLinkHrefID(), MCRLinkTableManager.ENTRY_TYPE_DERIVATE, "");
}
// add parent reference
if (structure.getParentID() != null) {
addReferenceLink(mcrId, structure.getParentID(), MCRLinkTableManager.ENTRY_TYPE_PARENT, "");
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRObject method checkLinkTargets.
public void checkLinkTargets() {
for (int i = 0; i < getMetadata().size(); i++) {
MCRMetaElement elm = getMetadata().getMetadataElement(i);
for (int j = 0; j < elm.size(); j++) {
MCRMetaInterface inf = elm.getElement(j);
if (inf instanceof MCRMetaClassification) {
String classID = ((MCRMetaClassification) inf).getClassId();
String categID = ((MCRMetaClassification) inf).getCategId();
boolean exists = MCRCategoryDAOFactory.getInstance().exist(new MCRCategoryID(classID, categID));
if (exists) {
continue;
}
MCRActiveLinkException activeLink = new MCRActiveLinkException("Failure while adding link!. Destination does not exist.");
String destination = classID + "##" + categID;
activeLink.addLink(getId().toString(), destination);
// throw activeLink;
// TODO: should trigger undo-Event
}
if (inf instanceof MCRMetaLinkID) {
MCRObjectID destination = ((MCRMetaLinkID) inf).getXLinkHrefID();
if (MCRMetadataManager.exists(destination)) {
continue;
}
MCRActiveLinkException activeLink = new MCRActiveLinkException("Failure while adding link!. Destination does not exist.");
activeLink.addLink(getId().toString(), destination.toString());
// throw activeLink;
// TODO: should trigger undo-Event
}
}
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRObjectService method setFromDOM.
/**
* This method read the XML input stream part from a DOM part for the
* structure data of the document.
*
* @param service
* a list of relevant DOM elements for the metadata
*/
public final void setFromDOM(Element service) {
// Date part
org.jdom2.Element dates_element = service.getChild("servdates");
dates.clear();
if (dates_element != null) {
List<Element> dateList = dates_element.getChildren();
for (Element dateElement : dateList) {
String date_element_name = dateElement.getName();
if (!date_element_name.equals("servdate")) {
continue;
}
MCRMetaISO8601Date date = new MCRMetaISO8601Date();
date.setFromDOM(dateElement);
setDate(date);
}
}
// Rule part
Element servacls = service.getChild("servacls");
if (servacls != null) {
List<Element> ruleList = servacls.getChildren();
for (Element ruleElement : ruleList) {
if (!ruleElement.getName().equals("servacl")) {
continue;
}
MCRMetaAccessRule user = new MCRMetaAccessRule();
user.setFromDOM(ruleElement);
rules.add(user);
}
}
// Flag part
org.jdom2.Element flagsElement = service.getChild("servflags");
if (flagsElement != null) {
List<Element> flagList = flagsElement.getChildren();
for (Element flagElement : flagList) {
if (!flagElement.getName().equals("servflag")) {
continue;
}
MCRMetaLangText flag = new MCRMetaLangText();
flag.setFromDOM(flagElement);
flags.add(flag);
}
}
org.jdom2.Element statesElement = service.getChild("servstates");
if (statesElement != null) {
List<Element> flagList = statesElement.getChildren();
for (Element stateElement : flagList) {
if (!stateElement.getName().equals("servstate")) {
continue;
}
MCRMetaClassification stateClass = new MCRMetaClassification();
stateClass.setFromDOM(stateElement);
state = new MCRCategoryID(stateClass.getClassId(), stateClass.getCategId());
}
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRFileMetadata method createXML.
public Element createXML() {
Element file = new Element("file");
file.setAttribute("name", name);
if (urn != null) {
Element urn = new Element("urn");
urn.setText(this.urn);
file.addContent(urn);
}
if (handle != null) {
Element handle = new Element("handle");
handle.setText(this.handle);
file.addContent(handle);
}
for (MCRCategoryID categid : categories) {
Element category = new Element("category");
category.setAttribute("id", categid.toString());
file.addContent(category);
}
return file;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImplTest method getLinksFromCategoryForType.
/**
* Test method for {@link org.mycore.datamodel.classifications2.impl.MCRCategLinkServiceImpl#getLinksFromCategoryForType(MCRCategoryID, String)}.
*/
@Test
public void getLinksFromCategoryForType() {
addTestLinks();
startNewTransaction();
MCRCategoryLinkImpl link = testLinks.iterator().next();
final String objectType = link.getObjectReference().getType();
final MCRCategoryID categoryID = link.getCategory().getId();
final String objectID = link.getObjectReference().getObjectID();
final Collection<String> result = SERVICE.getLinksFromCategoryForType(categoryID, objectType);
assertTrue("Did not find object: " + link.getObjectReference(), result.contains(objectID));
for (String id : result) {
String type = getType(id);
assertEquals("Wrong return type detected: " + id, objectType, type);
}
}
Aggregations