Search in sources :

Example 61 with MCRCategoryID

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

the class MCRCategoryListTypeAdapter method categListToJsonArray.

private JsonElement categListToJsonArray(List<MCRCategory> categList, Map<MCRCategoryID, Boolean> linkMap) {
    JsonArray categJsonArray = new JsonArray();
    for (MCRCategory categ : categList) {
        Boolean hasLink = linkMap.get(categ.getId());
        JsonElement element = createCategRefJSONObj(categ, hasLink);
        categJsonArray.add(element);
    }
    return categJsonArray;
}
Also used : JsonArray(com.google.gson.JsonArray) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) JsonElement(com.google.gson.JsonElement)

Example 62 with MCRCategoryID

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

the class MCRClassificationWritePermission method isPermitted.

/* (non-Javadoc)
     * @see org.mycore.frontend.jersey.filter.access.MCRResourceAccessChecker#isPermitted(com.sun.jersey.spi.container.ContainerRequest)
     */
@Override
public boolean isPermitted(ContainerRequestContext request) {
    String value = convertStreamToString(request.getEntityStream());
    try {
        // Set<MCRCategoryID> categories = MCRCategUtils.getRootCategoryIDs(value);
        HashMap<MCRCategoryID, String> categories = MCRCategUtils.getCategoryIDMap(value);
        if (categories == null) {
            LOGGER.error("Could not parse {}", value);
            return false;
        }
        for (Map.Entry<MCRCategoryID, String> categoryEntry : categories.entrySet()) {
            MCRCategoryID category = categoryEntry.getKey();
            String state = categoryEntry.getValue();
            if (!hasPermission(category, state)) {
                LOGGER.info("Permission {} denied on classification {}", category.getRootID(), category);
                return false;
            }
        }
        return true;
    } catch (Exception exc) {
        throw new WebApplicationException(exc, Response.status(Status.INTERNAL_SERVER_ERROR).entity("Unable to check permission for request " + request.getUriInfo().getRequestUri() + " containing entity value " + value).build());
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) Map(java.util.Map) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 63 with MCRCategoryID

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

the class GsonSerializationTest method createCateg.

protected MCRCategoryImpl createCateg(String rootID, String id2, String text) {
    MCRCategoryImpl mcrCategoryImpl = new MCRCategoryImpl();
    MCRCategoryID id = new MCRCategoryID(rootID, id2);
    mcrCategoryImpl.setId(id);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("de", text + "_de", "desc_" + text + "_de"));
    labels.add(new MCRLabel("en", text + "_en", "desc_" + text + "_en"));
    mcrCategoryImpl.setLabels(labels);
    return mcrCategoryImpl;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 64 with MCRCategoryID

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

the class CategoryDAOMock method createCategory.

private MCRJSONCategory createCategory(String rootID, String categID, MCRCategoryID parentID) {
    MCRCategoryID id = new MCRCategoryID(rootID, categID);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("de", id + "_text", id + "_descr"));
    labels.add(new MCRLabel("en", id + "_text", id + "_descr"));
    MCRJSONCategory newCategory = new MCRJSONCategory();
    newCategory.setId(id);
    newCategory.setLabels(labels);
    newCategory.setParentID(parentID);
    return newCategory;
}
Also used : MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 65 with MCRCategoryID

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

the class MCRClassificationEditorResource method getCategory.

private String getCategory(MCRCategoryID id) {
    if (!CATEGORY_DAO.exist(id)) {
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    MCRCategory category = CATEGORY_DAO.getCategory(id, 1);
    if (!(category instanceof MCRJSONCategory)) {
        category = new MCRJSONCategory(category);
    }
    Gson gson = MCRJSONManager.instance().createGson();
    return gson.toJson(category);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) WebApplicationException(javax.ws.rs.WebApplicationException) Gson(com.google.gson.Gson)

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