Search in sources :

Example 21 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRMODSClassificationSupport method getClassCategParentLink.

public static String getClassCategParentLink(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return "";
    }
    final Element source = (Element) sources.item(0);
    MCRCategoryID category = MCRClassMapper.getCategoryID(source);
    if (category == null) {
        return "";
    }
    String id;
    try {
        id = MCRXMLFunctions.encodeURIPath(category.getID());
    } catch (URISyntaxException e) {
        /* This should be impossible! */
        throw new MCRException(e);
    }
    return MessageFormat.format("classification:metadata:0:parents:{0}:{1}", category.getRootID(), id);
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException)

Example 22 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRMODSClassificationSupport method getClassCategLink.

public static String getClassCategLink(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return "";
    }
    final Element source = (Element) sources.item(0);
    MCRCategoryID category = MCRClassMapper.getCategoryID(source);
    if (category == null) {
        return "";
    }
    String id;
    try {
        id = MCRXMLFunctions.encodeURIPath(category.getID());
    } catch (URISyntaxException e) {
        /* This should be impossible! */
        throw new MCRException(e);
    }
    return MessageFormat.format("classification:metadata:0:children:{0}:{1}", category.getRootID(), id);
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException)

Example 23 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRSolrClassificationUtil method reindex.

public static void reindex(Collection<MCRCategoryID> categoryIds) {
    List<MCRCategory> categoryList = new ArrayList<>(categoryIds.size());
    MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
    for (MCRCategoryID categoryId : categoryIds) {
        MCRCategory category = dao.getCategory(categoryId, 0);
        categoryList.add(category);
    }
    reindex(categoryList.toArray(new MCRCategory[categoryList.size()]));
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) ArrayList(java.util.ArrayList)

Example 24 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRSolrFileIndexBaseAccumulator method accumulate.

@Override
public void accumulate(SolrInputDocument doc, Path input, BasicFileAttributes attr) throws IOException {
    doc.setField("id", input.toUri().toString());
    String absolutePath = '/' + input.subpath(0, input.getNameCount()).toString();
    try {
        // check if this is an MCRPath -> more metadata
        MCRPath mcrPath = MCRPath.toMCRPath(input);
        MCRObjectID mcrObjID = MCRMetadataManager.getObjectId(MCRObjectID.getInstance(mcrPath.getOwner()), 10, TimeUnit.SECONDS);
        if (mcrObjID == null) {
            LOGGER.warn("Could not determine MCRObject for file {}", absolutePath);
            doc.setField("returnId", mcrPath.getOwner());
        } else {
            doc.setField("returnId", mcrObjID.toString());
            doc.setField("objectProject", mcrObjID.getProjectId());
        }
        String ownerID = mcrPath.getOwner();
        doc.setField("derivateID", ownerID);
        doc.setField("derivateModified", getDerivateModified(ownerID));
        Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(mcrPath));
        HashSet<MCRCategoryID> linkedCategories = new HashSet<>(linksFromReference);
        for (MCRCategoryID category : linksFromReference) {
            for (MCRCategory parent : CATEGORY_DAO.getParents(category)) {
                linkedCategories.add(parent.getId());
            }
        }
        for (MCRCategoryID category : linkedCategories) {
            doc.addField("fileCategory", category.toString());
        }
    } catch (ProviderMismatchException e) {
        LOGGER.warn("Cannot build all fields as input is not an instance of MCRPath: {}", input);
    }
    doc.setField("objectType", "data_file");
    doc.setField("fileName", input.getFileName().toString());
    doc.setField("filePath", absolutePath);
    doc.setField("stream_size", attr.size());
    doc.setField("stream_name", absolutePath);
    doc.setField("stream_source_info", input.toString());
    doc.setField("stream_content_type", MCRContentTypes.probeContentType(input));
    doc.setField("extension", Files.getFileExtension(input.getFileName().toString()));
    MCRISO8601Date iDate = new MCRISO8601Date();
    iDate.setDate(new Date(attr.lastModifiedTime().toMillis()));
    doc.setField("modified", iDate.getISOString());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) ProviderMismatchException(java.nio.file.ProviderMismatchException) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date) HashSet(java.util.HashSet)

Example 25 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRSolrCategory method toSolrDocument.

public SolrInputDocument toSolrDocument() {
    SolrInputDocument doc = new SolrInputDocument();
    LinkedList<MCRCategory> ancestors = MCRSolrClassificationUtil.getAncestors(category);
    MCRCategory parent = !ancestors.isEmpty() ? ancestors.getLast() : null;
    // ids
    MCRCategoryID id = category.getId();
    doc.setField("id", id.toString());
    doc.setField("classification", id.getRootID());
    doc.setField("type", "node");
    if (category.isCategory()) {
        doc.setField("category", id.getID());
    }
    // labels
    Set<MCRLabel> labels = category.getLabels();
    for (MCRLabel label : labels) {
        doc.addField("label." + label.getLang(), label.getText());
    }
    // children
    if (category.hasChildren()) {
        for (MCRCategory child : category.getChildren()) {
            doc.addField("children", child.getId().toString());
        }
    }
    // parent
    if (parent != null) {
        doc.setField("parent", parent.getId().toString());
        doc.setField("index", parent.getChildren().indexOf(category));
    }
    // ancestors
    for (MCRCategory ancestor : ancestors) {
        doc.addField("ancestors", ancestor.getId().toString());
    }
    return doc;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

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