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;
}
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());
}
}
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;
}
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;
}
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);
}
Aggregations