Search in sources :

Example 1 with MCRMetaClassification

use of org.mycore.datamodel.metadata.MCRMetaClassification 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 MCRMetaClassification

use of org.mycore.datamodel.metadata.MCRMetaClassification in project mycore by MyCoRe-Org.

the class MCRClassificationMappingEventHandler method addMappings.

private void addMappings(MCRMetaElement mappings, MCRCategory categ) {
    if (categ != null) {
        categ.getLabel("x-mapping").ifPresent(label -> {
            String[] str = label.getText().split("\\s");
            for (String s : str) {
                if (s.contains(":")) {
                    String[] mapClass = s.split(":");
                    MCRMetaClassification metaClass = new MCRMetaClassification("mapping", 0, null, mapClass[0], mapClass[1]);
                    mappings.addMetaObject(metaClass);
                }
            }
        });
    }
}
Also used : MCRMetaClassification(org.mycore.datamodel.metadata.MCRMetaClassification)

Aggregations

MCRMetaClassification (org.mycore.datamodel.metadata.MCRMetaClassification)2 HashSet (java.util.HashSet)1 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1 MCRMetaDerivateLink (org.mycore.datamodel.metadata.MCRMetaDerivateLink)1 MCRMetaLink (org.mycore.datamodel.metadata.MCRMetaLink)1 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCRObjectMetadata (org.mycore.datamodel.metadata.MCRObjectMetadata)1 MCRObjectStructure (org.mycore.datamodel.metadata.MCRObjectStructure)1