Search in sources :

Example 11 with MCRCategLinkReference

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

the class MCRRoleManager method storeRoleAssignments.

/**
 * Stores role membership information of the user
 *
 * @param user the user
 */
static void storeRoleAssignments(MCRUser user) {
    MCRCategLinkReference ref = getLinkID(user);
    LinkedList<MCRCategoryID> categories = new LinkedList<>();
    for (String roleID : user.getSystemRoleIDs()) {
        MCRCategoryID categID = new MCRCategoryID(MCRUser2Constants.ROLE_CLASSID.getRootID(), roleID);
        categories.add(categID);
    }
    for (String roleID : user.getExternalRoleIDs()) {
        MCRCategoryID categID = MCRCategoryID.fromString(roleID);
        categories.add(categID);
    }
    LOGGER.info("Assigning {} to these roles: {}", user.getUserID(), categories);
    CATEG_LINK_SERVICE.setLinks(ref, categories);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) LinkedList(java.util.LinkedList)

Example 12 with MCRCategLinkReference

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

the class MCRCategLinkServiceImplTest method isInCategory.

@Test
public void isInCategory() {
    MCRCategoryImpl germany = (MCRCategoryImpl) category.getChildren().get(0).getChildren().get(0);
    MCRCategoryImpl europe = (MCRCategoryImpl) category.getChildren().get(0);
    MCRCategoryImpl asia = (MCRCategoryImpl) category.getChildren().get(1);
    MCRCategLinkReference jena = new MCRCategLinkReference("Jena", "city");
    addTestLinks();
    startNewTransaction();
    assertTrue("Jena should be in Germany", SERVICE.isInCategory(jena, germany.getId()));
    assertTrue("Jena should be in Europe", SERVICE.isInCategory(jena, europe.getId()));
    assertFalse("Jena should not be in Asia", SERVICE.isInCategory(jena, asia.getId()));
}
Also used : MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) Test(org.junit.Test)

Example 13 with MCRCategLinkReference

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

the class MCRClassificationUtils method isInCollection.

public static boolean isInCollection(String mcrId, String collection) {
    MCRObjectID mcrObjectID = MCRObjectID.getInstance(mcrId);
    MCRCategoryID collectionID = new MCRCategoryID(MCRConstants.COLLECTION_CLASS_ID.getRootID(), collection);
    MCRCategLinkReference reference = new MCRCategLinkReference(mcrObjectID);
    return LINK_SERVICE.isInCategory(reference, collectionID);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 14 with MCRCategLinkReference

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

the class MCRCreatorRuleStrategy method objectStatusIsSubmitted.

private static boolean objectStatusIsSubmitted(MCRObjectID mcrObjectID) {
    MCRCategLinkReference reference = new MCRCategLinkReference(mcrObjectID);
    boolean isSubmitted = false;
    if (SUBMITTED_CATEGORY == null) {
        return false;
    }
    String[] submittedCategoriesSplitted = SUBMITTED_CATEGORY.split(",");
    for (String submittedCategoryID : submittedCategoriesSplitted) {
        String categoryId = submittedCategoryID.trim();
        MCRCategoryID submittedCategory = MCRCategoryID.fromString(categoryId);
        if (LINK_SERVICE.isInCategory(reference, submittedCategory)) {
            isSubmitted = true;
        }
    }
    return isSubmitted;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 15 with MCRCategLinkReference

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

the class MCRFileMetaEventHandler method handleDerivateCreated.

@Override
protected void handleDerivateCreated(MCREvent evt, MCRDerivate der) {
    MCRObjectID derivateID = der.getId();
    MCRObjectDerivate objectDerivate = der.getDerivate();
    List<MCRFileMetadata> fileMetadata = objectDerivate.getFileMetadata();
    for (MCRFileMetadata metadata : fileMetadata) {
        Collection<MCRCategoryID> categories = metadata.getCategories();
        if (!categories.isEmpty()) {
            MCRPath path = MCRPath.getPath(derivateID.toString(), metadata.getName());
            MCRCategLinkReference linkReference = new MCRCategLinkReference(path);
            CATEGLINK_SERVICE.setLinks(linkReference, categories);
        }
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Aggregations

MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)19 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)5 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)5 EntityManager (javax.persistence.EntityManager)3 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)3 MCRPath (org.mycore.datamodel.niofs.MCRPath)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Element (org.jdom2.Element)2 Test (org.junit.Test)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 ProviderMismatchException (java.nio.file.ProviderMismatchException)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1