Search in sources :

Example 1 with MCRCategoryID

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, "");
    }
}
Also used : MCRMetaClassification(org.mycore.datamodel.metadata.MCRMetaClassification) MCRMetaDerivateLink(org.mycore.datamodel.metadata.MCRMetaDerivateLink) MCRObjectMetadata(org.mycore.datamodel.metadata.MCRObjectMetadata) MCRMetaLink(org.mycore.datamodel.metadata.MCRMetaLink) MCRObjectStructure(org.mycore.datamodel.metadata.MCRObjectStructure) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) HashSet(java.util.HashSet)

Example 2 with MCRCategoryID

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
            }
        }
    }
}
Also used : MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 3 with MCRCategoryID

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());
        }
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 4 with MCRCategoryID

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;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element)

Example 5 with MCRCategoryID

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);
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Test(org.junit.Test)

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4