Search in sources :

Example 6 with MCRLabel

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

the class MCRCategoryTypeAdapter method serialize.

@Override
public JsonElement serialize(MCRJSONCategory category, Type arg1, JsonSerializationContext contextSerialization) {
    JsonObject rubricJsonObject = new JsonObject();
    MCRCategoryID id = category.getId();
    if (id != null) {
        rubricJsonObject.add(ID, contextSerialization.serialize(id));
    }
    Set<MCRLabel> labels = category.getLabels();
    rubricJsonObject.add(LABELS, contextSerialization.serialize(new MCRLabelSetWrapper(labels)));
    URI uri = category.getURI();
    if (uri != null) {
        rubricJsonObject.addProperty(URISTR, uri.toString());
    }
    if (category.hasChildren()) {
        List<MCRCategory> children = category.getChildren();
        Map<MCRCategoryID, Boolean> linkMap = getLinkService().hasLinks(category);
        if (linkMap.values().contains(true)) {
            rubricJsonObject.addProperty(HASLINK, true);
        }
        rubricJsonObject.add(CHILDREN, contextSerialization.serialize(new MCRCategoryListWrapper(children, linkMap)));
    }
    return rubricJsonObject;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) URI(java.net.URI)

Example 7 with MCRLabel

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

the class MCRLabelSetTypeAdapter method labelsToJsonArray.

private JsonArray labelsToJsonArray(Set<MCRLabel> labels) {
    JsonArray labelJsonArray = new JsonArray();
    for (MCRLabel label : labels) {
        JsonObject labelJsonObj = labelToJsonObj(label);
        labelJsonArray.add(labelJsonObj);
    }
    return labelJsonArray;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 8 with MCRLabel

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

the class MCRClassMapper method getAuthority.

private static String getAuthority(String rootID) {
    long classLastModified = Math.max(0, DAO.getLastModified(rootID));
    String auth = authCache.getIfUpToDate(rootID, classLastModified);
    if (auth == null) {
        MCRCategory rootCategory = DAO.getRootCategory(MCRCategoryID.rootID(rootID), 0);
        auth = rootCategory.getLabel("x-auth").map(MCRLabel::getText).orElse("");
        authCache.put(rootID, auth, classLastModified);
    }
    return auth.isEmpty() ? null : auth;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 9 with MCRLabel

use of org.mycore.datamodel.classifications2.MCRLabel 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)

Example 10 with MCRLabel

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

the class MCRClassification2Commands method repairEmptyLabels.

@MCRCommand(syntax = "repair category with empty labels", help = "fixes all categories with no labels (adds a label with categid as @text for default lang)", order = 110)
public static void repairEmptyLabels() {
    Session session = MCRHIBConnection.instance().getSession();
    String deleteEmptyLabels = "delete from {h-schema}MCRCategoryLabels where text is null or trim(text) = ''";
    int affected = session.createNativeQuery(deleteEmptyLabels).executeUpdate();
    LOGGER.info("Deleted {} labels.", affected);
    String sqlQuery = "select cat.classid,cat.categid from {h-schema}MCRCategory cat left outer join {h-schema}MCRCategoryLabels label on cat.internalid = label.category where label.text is null";
    @SuppressWarnings("unchecked") List<Object[]> list = session.createNativeQuery(sqlQuery).getResultList();
    for (Object resultList : list) {
        Object[] arrayOfResults = (Object[]) resultList;
        String classIDString = (String) arrayOfResults[0];
        String categIDString = (String) arrayOfResults[1];
        MCRCategoryID mcrCategID = new MCRCategoryID(classIDString, categIDString);
        MCRLabel mcrCategLabel = new MCRLabel(MCRConstants.DEFAULT_LANG, categIDString, null);
        MCRCategoryDAOFactory.getInstance().setLabel(mcrCategID, mcrCategLabel);
        LOGGER.info("fixing category with class ID \"{}\" and category ID \"{}\"", classIDString, categIDString);
    }
    LOGGER.info("Fixing category labels completed!");
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Session(org.hibernate.Session) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)30 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)14 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)8 Test (org.junit.Test)6 JsonObject (com.google.gson.JsonObject)4 Element (org.jdom2.Element)4 MCRException (org.mycore.common.MCRException)3 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonArray (com.google.gson.JsonArray)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1