use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method exportAllPermissionsToFile.
/**
* This method just export the permissions to a file
*
* @param filename
* the file written to
*/
@MCRCommand(syntax = "export all permissions to file {0}", help = "Export all permissions from the Access Control System to the file {0}.", order = 50)
public static void exportAllPermissionsToFile(String filename) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Element mcrpermissions = new Element("mcrpermissions");
mcrpermissions.addNamespaceDeclaration(XSI_NAMESPACE);
mcrpermissions.addNamespaceDeclaration(XLINK_NAMESPACE);
mcrpermissions.setAttribute("noNamespaceSchemaLocation", "MCRPermissions.xsd", XSI_NAMESPACE);
Document doc = new Document(mcrpermissions);
Collection<String> permissions = AI.getPermissions();
for (String permission : permissions) {
Element mcrpermission = new Element("mcrpermission");
mcrpermission.setAttribute("name", permission);
String ruleDescription = AI.getRuleDescription(permission);
if (!ruleDescription.equals("")) {
mcrpermission.setAttribute("ruledescription", ruleDescription);
}
Element rule = AI.getRule(permission);
mcrpermission.addContent(rule);
mcrpermissions.addContent(mcrpermission);
}
File file = new File(filename);
if (file.exists()) {
LOGGER.warn("File {} yet exists, overwrite.", filename);
}
FileOutputStream fos = new FileOutputStream(file);
LOGGER.info("Writing to file {} ...", filename);
String mcr_encoding = CONFIG.getString("MCR.Metadata.DefaultEncoding", DEFAULT_ENCODING);
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding(mcr_encoding));
out.output(doc, fos);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionUpdateForSelected.
/**
* updates the permissions for all ids of a given MCRObjectID-Type and for a
* given permission type with a given rule
*
* @param permission
* String type of permission like read, writedb, etc.
* @param strFileRule
* String the path to the xml file, that contains the rule
* @param description
* String give a special description, if the semantics of your
* rule is multiple used
*/
@MCRCommand(syntax = "update permission {0} for selected with rulefile {1} described by {2}", help = "The command updates access rule for a given permission and all ids of a given MCRObject-Type with a given special rule", order = 80)
public static void permissionUpdateForSelected(String permission, String strFileRule, String description) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Element rule = getRuleFromFile(strFileRule);
if (rule == null) {
return;
}
for (String id : MCRObjectCommands.getSelectedObjectIDs()) {
AI.addRule(id, permission, rule, description);
}
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionDeleteForID.
/**
* delete a given permission for a given id
*
* @param permission
* String type of permission like read, writedb, etc.
* @param id
* String the id of the object the rule is assigned to
*/
@MCRCommand(syntax = "delete permission {0} for id {1}", help = "The command delete access rule for a given id of a given permission", order = 110)
public static void permissionDeleteForID(String permission, String id) {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
AI.removeRule(id, permission);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIFS2Commands method repairUnicodeInContentStores.
@MCRCommand(syntax = "repair unicode in content stores {0}", help = "this fixes consequences of MCR-1423 in content" + " stores . If {0} is false then nothing will be done (dry run).")
public static void repairUnicodeInContentStores(String execute) {
boolean dry = execute.toLowerCase(Locale.ROOT).equals(Boolean.FALSE.toString().toLowerCase(Locale.ROOT));
MCRContentStoreFactory.getAvailableStores().forEach((name, cs) -> {
LOGGER.info("{} store: {} ", dry ? "would fix" : "fixing", name);
try {
Path path = cs.getBaseDir().toPath();
LOGGER.info("Starting with path : {}", path);
java.nio.file.Files.walkFileTree(path, new MCRUnicodeFilenameNormalizer(dry));
} catch (IOException e) {
throw new MCRException("Error while get basedir of content store " + name, e);
}
});
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIFS2Commands method repairUnicodeInDatabase.
@MCRCommand(syntax = "repair unicode in database {0}", help = "this fixes consequences of MCR-1423 in Database. If " + "{0} is false then nothing will be done (dry run).")
public static void repairUnicodeInDatabase(String execute) {
boolean dry = execute.toLowerCase(Locale.ROOT).equals(Boolean.FALSE.toString().toLowerCase(Locale.ROOT));
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MCRFSNODES> getQuery = cb.createQuery(MCRFSNODES.class);
List<MCRFSNODES> resultList = em.createQuery(getQuery.select(getQuery.from(MCRFSNODES.class))).getResultList();
resultList.stream().forEach(node -> {
String unnormalName = node.getName();
String normalName = MCRXMLFunctions.normalizeUnicode(unnormalName);
if (!unnormalName.equals(normalName)) {
LOGGER.info("{} node {} with name {}", (dry) ? "Would Fix" : "Fixing", node.getId(), unnormalName);
if (!dry) {
node.setName(normalName);
}
}
});
}
Aggregations