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