Search in sources :

Example 66 with MCRCategoryID

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

the class MCRCategUtils method getCategoryIDMap.

public static HashMap<MCRCategoryID, String> getCategoryIDMap(String json) {
    HashMap<MCRCategoryID, String> categories = new HashMap<>();
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (jsonStreamParser.hasNext()) {
        JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
        for (JsonElement jsonElement : saveObjArray) {
            // jsonObject.item.id.rootid
            JsonObject root = jsonElement.getAsJsonObject();
            String rootId = root.getAsJsonObject("item").getAsJsonObject("id").getAsJsonPrimitive("rootid").getAsString();
            String state = root.getAsJsonPrimitive("state").getAsString();
            JsonElement parentIdJSON = root.get("parentId");
            if (parentIdJSON != null && parentIdJSON.isJsonPrimitive() && "_placeboid_".equals(parentIdJSON.getAsString())) {
                state = "new";
            }
            categories.put(MCRCategoryID.rootID(rootId), state);
        }
    } else {
        return null;
    }
    return categories;
}
Also used : JsonArray(com.google.gson.JsonArray) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonStreamParser(com.google.gson.JsonStreamParser)

Example 67 with MCRCategoryID

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

the class MCRMetadataHistoryManager method objectIsHidden.

static boolean objectIsHidden(MCRObject obj) {
    MCRCategoryID state = obj.getService().getState();
    if (state == null) {
        LogManager.getLogger().debug("{} is visible as it does not use a service state.", obj.getId());
        return false;
    }
    boolean hidden = !"published".equals(state.getID());
    LogManager.getLogger().debug("{} is hidden due to service state '{}': {}", obj.getId(), state, hidden);
    return hidden;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 68 with MCRCategoryID

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

the class MCRClassification2Commands method checkMissingParent.

private static void checkMissingParent(String classID, List<String> log) {
    Session session = MCRHIBConnection.instance().getSession();
    String sqlQuery = "select cat.categid from {h-schema}MCRCategory cat WHERE cat.classid='" + classID + "' and cat.level > 0 and cat.parentID is NULL";
    @SuppressWarnings("unchecked") List<String> list = session.createNativeQuery(sqlQuery).getResultList();
    for (String categIDString : list) {
        log.add("parentID is null for category " + new MCRCategoryID(classID, categIDString));
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Session(org.hibernate.Session)

Example 69 with MCRCategoryID

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

the class MCRClassification2Commands method exportAll.

/**
 * Save all MCRClassifications.
 *
 * @param dirname
 *            the directory name to store all classifications
 * @param style
 *            the name part of the stylesheet like <em>style</em>
 *            -classification.xsl
 * @return false if an error was occured, else true
 */
@MCRCommand(syntax = "export all classifications to directory {0} with {1}", help = "The command store all classifications to the directory with name {0} with the stylesheet {1}-object.xsl. For {1} save is the default.", order = 70)
public static boolean exportAll(String dirname, String style) throws Exception {
    List<MCRCategoryID> allClassIds = DAO.getRootCategoryIDs();
    boolean ret = false;
    for (MCRCategoryID id : allClassIds) {
        ret = ret & export(id.getRootID(), dirname, style);
    }
    return ret;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 70 with MCRCategoryID

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

the class MCRClassification2Commands method checkAllClassifications.

@MCRCommand(syntax = "check all classifications", help = "checks if all redundant information are stored without conflicts", order = 140)
public static List<String> checkAllClassifications() {
    List<MCRCategoryID> classifications = MCRCategoryDAOFactory.getInstance().getRootCategoryIDs();
    List<String> commands = new ArrayList<>(classifications.size());
    for (MCRCategoryID id : classifications) {
        commands.add("check classification " + id.getRootID());
    }
    return commands;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) ArrayList(java.util.ArrayList) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

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