Search in sources :

Example 31 with MCRCategoryID

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();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with MCRCategoryID

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);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 33 with MCRCategoryID

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;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) HashMap(java.util.HashMap)

Example 34 with MCRCategoryID

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()));
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRJerseyTest(org.mycore.frontend.jersey.resources.MCRJerseyTest) Test(org.junit.Test)

Example 35 with MCRCategoryID

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);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Document(org.jdom2.Document)

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