Search in sources :

Example 16 with MCRLabel

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

the class MCRUserCommands method initSuperuser.

/**
 * This method initializes the user and role system an creates a superuser with values set in
 * mycore.properties.private As 'super' default, if no properties were set, mcradmin with password mycore will be
 * used.
 */
@MCRCommand(syntax = "init superuser", help = "Initializes the user system. This command runs only if the user database does not exist.", order = 30)
public static List<String> initSuperuser() {
    final String suser = CONFIG.getString("MCR.Users.Superuser.UserName");
    final String spasswd = CONFIG.getString("MCR.Users.Superuser.UserPasswd");
    final String srole = CONFIG.getString("MCR.Users.Superuser.GroupName");
    if (MCRUserManager.exists(suser)) {
        LOGGER.error("The superuser already exists!");
        return null;
    }
    // the superuser role
    try {
        Set<MCRLabel> labels = new HashSet<>();
        labels.add(new MCRLabel("en", "The superuser role", null));
        MCRRole mcrRole = new MCRRole(srole, labels);
        MCRRoleManager.addRole(mcrRole);
    } catch (Exception e) {
        throw new MCRException("Can't create the superuser role.", e);
    }
    LOGGER.info("The role {} is installed.", srole);
    // the superuser
    try {
        MCRUser mcrUser = new MCRUser(suser);
        mcrUser.setRealName("Superuser");
        mcrUser.assignRole(srole);
        MCRUserManager.updatePasswordHashToSHA256(mcrUser, spasswd);
        MCRUserManager.createUser(mcrUser);
    } catch (Exception e) {
        throw new MCRException("Can't create the superuser.", e);
    }
    LOGGER.info(MessageFormat.format("The user {0} with password {1} is installed.", suser, spasswd));
    return Collections.singletonList("change to user " + suser + " with " + spasswd);
}
Also used : MCRException(org.mycore.common.MCRException) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) MCRException(org.mycore.common.MCRException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) HashSet(java.util.HashSet) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 17 with MCRLabel

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

the class MCRCategoryDAOImplTest method newCategory.

private MCRCategoryImpl newCategory(MCRCategoryID id, String description) {
    MCRCategoryImpl newCateg = new MCRCategoryImpl();
    newCateg.setId(id);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("en", id.toString(), description));
    newCateg.setLabels(labels);
    return newCateg;
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 18 with MCRLabel

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

the class MCRCategoryDAOImplTest method getCategoriesByLabel.

@Test
public void getCategoriesByLabel() {
    addWorldClassification();
    MCRCategory find = category.getChildren().get(0).getChildren().get(0);
    MCRCategory dontFind = category.getChildren().get(1);
    MCRLabel label = find.getLabels().iterator().next();
    List<MCRCategory> results = DAO.getCategoriesByLabel(category.getId(), label.getLang(), label.getText());
    assertFalse("No search results found", results.isEmpty());
    assertTrue("Could not find Category: " + find.getId(), results.get(0).getLabels().contains(label));
    assertTrue("No search result expected.", DAO.getCategoriesByLabel(dontFind.getId(), label.getLang(), label.getText()).isEmpty());
    results = DAO.getCategoriesByLabel(label.getLang(), label.getText());
    assertFalse("No search results found", results.isEmpty());
    assertTrue("Could not find Category: " + find.getId(), results.get(0).getLabels().contains(label));
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 19 with MCRLabel

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

the class MCRCategoryDAOImplTest method testReplaceCategoryNewParent.

/**
 * tests top category child to new parent
 */
public void testReplaceCategoryNewParent() {
    addWorldClassification();
    MCRCategory europe = category.getChildren().get(0);
    MCRCategoryImpl test = new MCRCategoryImpl();
    test.setId(new MCRCategoryID(category.getId().getRootID(), "test"));
    test.setLabels(new HashSet<>());
    test.getLabels().add(new MCRLabel("de", "JUnit testcase", null));
    category.getChildren().add(test);
    category.getChildren().remove(0);
    test.getChildren().add(europe);
    DAO.replaceCategory(category);
    startNewTransaction();
    MCRCategory rootNode = getRootCategoryFromSession();
    assertEquals("Category count does not match.", countNodes(category), countNodes(rootNode));
    assertEquals("Label count does not match.", category.getChildren().get(0).getLabels().size(), rootNode.getChildren().get(0).getLabels().size());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 20 with MCRLabel

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

the class MCRCategoryDAOImplTest method addCategoryToPosition.

/**
 * Test case for https://sourceforge.net/p/mycore/bugs/664/
 */
@Test
public void addCategoryToPosition() {
    addWorldClassification();
    MCRCategoryImpl america = new MCRCategoryImpl();
    MCRCategoryID categoryID = new MCRCategoryID(category.getId().getRootID(), "America");
    america.setId(categoryID);
    america.setLabels(new HashSet<>());
    america.getLabels().add(new MCRLabel("de", "Amerika", null));
    america.getLabels().add(new MCRLabel("en", "America", null));
    DAO.addCategory(category.getId(), america, 1);
    startNewTransaction();
    america = MCRCategoryDAOImpl.getByNaturalID(getEntityManager().get(), america.getId());
    assertNotNull(categoryID + " was not added to database.", america);
    assertEquals("invalid position in parent", 1, america.getPositionInParent());
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Aggregations

MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)30 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)14 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)8 Test (org.junit.Test)6 JsonObject (com.google.gson.JsonObject)4 Element (org.jdom2.Element)4 MCRException (org.mycore.common.MCRException)3 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonArray (com.google.gson.JsonArray)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1