use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRClassificationEditorResource method getClassification.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClassification() {
Gson gson = MCRJSONManager.instance().createGson();
List<MCRCategory> rootCategories = new LinkedList<>(CATEGORY_DAO.getRootCategories());
rootCategories.removeIf(category -> !MCRAccessManager.checkPermission(category.getId().getRootID(), PERMISSION_WRITE));
if (rootCategories.isEmpty() && !MCRAccessManager.checkPermission(MCRClassificationUtils.CREATE_CLASS_PERMISSION)) {
return Response.status(Status.UNAUTHORIZED).build();
}
Map<MCRCategoryID, Boolean> linkMap = CATEG_LINK_SERVICE.hasLinks(null);
String json = gson.toJson(new MCRCategoryListWrapper(rootCategories, linkMap));
return Response.ok(json).build();
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class CategoryDAOMock method deleteCategory.
@Override
public void deleteCategory(MCRCategoryID id) {
MCRCategory mcrCategory = categMap.get(id);
for (MCRCategory child : mcrCategory.getChildren()) {
categMap.remove(child.getId());
}
categMap.remove(id);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class CategoryLinkServiceMock method hasLinks.
@Override
public Map<MCRCategoryID, Boolean> hasLinks(MCRCategory category) {
List<MCRCategory> categories;
if (category == null) {
categories = MCRCategoryDAOFactory.getInstance().getRootCategories();
} else {
categories = category.getChildren();
}
Map<MCRCategoryID, Boolean> linkMap = new HashMap<>();
int i = 0;
for (MCRCategory mcrCategory : categories) {
boolean haslink = false;
if (i++ % 2 == 0) {
haslink = true;
}
linkMap.put(mcrCategory.getId(), haslink);
}
return linkMap;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRClassificationEditorResourceTest method getSingleCategory.
@Test
public void getSingleCategory() throws Exception {
Collection<MCRCategory> categs = categDAO.getCategs();
for (MCRCategory mcrCategory : categs) {
MCRCategoryID id = mcrCategory.getId();
String path = id.getRootID();
String categID = id.getID();
if (categID != null && !"".equals(categID)) {
path = path + "/" + categID;
}
String categoryJsonStr = target("/classifications/" + path).request().get(String.class);
MCRJSONCategory retrievedCateg = MCRJSONManager.instance().createGson().fromJson(categoryJsonStr, MCRJSONCategory.class);
String errorMsg = MessageFormat.format("We want to retrieve the category {0} but it was {1}", id, retrievedCateg.getId());
assertTrue(errorMsg, id.equals(retrievedCateg.getId()));
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRFile method createXML.
/**
* Build a XML representation of all technical metadata of this MCRFile and its MCRAudioVideoExtender, if present. That xml can be used for indexing this
* data.
*/
public Document createXML() {
Element root = new Element("file");
root.setAttribute("id", getID());
root.setAttribute("owner", getOwnerID());
root.setAttribute("name", getName());
String absolutePath = getAbsolutePath();
root.setAttribute("path", absolutePath);
root.setAttribute("size", Long.toString(getSize()));
root.setAttribute("extension", getExtension());
root.setAttribute("contentTypeID", getContentTypeID());
root.setAttribute("contentType", getContentType().getLabel());
root.setAttribute("returnId", getMCRObjectID().toString());
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(getCategLinkReference(MCRObjectID.getInstance(getOwnerID()), absolutePath));
for (MCRCategoryID category : linksFromReference) {
Element catEl = new Element("category");
catEl.setAttribute("id", category.toString());
root.addContent(catEl);
}
MCRISO8601Date iDate = new MCRISO8601Date();
iDate.setDate(getLastModified().getTime());
root.setAttribute("modified", iDate.getISOString());
if (hasAudioVideoExtender()) {
MCRAudioVideoExtender ext = getAudioVideoExtender();
root.setAttribute("bitRate", String.valueOf(ext.getBitRate()));
root.setAttribute("frameRate", String.valueOf(ext.getFrameRate()));
root.setAttribute("duration", ext.getDurationTimecode());
root.setAttribute("mediaType", (ext.hasVideoStream() ? "video" : "audio"));
}
return new Document(root);
}
Aggregations