use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRSolrCategoryDAO method deleteCategory.
@Override
public void deleteCategory(MCRCategoryID id) {
MCRCategory category = MCRCategoryDAOFactory.getInstance().getCategory(id, 0);
MCRCategory parent = category.getParent();
super.deleteCategory(id);
solrDelete(id, parent);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method repairEmptyLabels.
@MCRCommand(syntax = "repair category with empty labels", help = "fixes all categories with no labels (adds a label with categid as @text for default lang)", order = 110)
public static void repairEmptyLabels() {
Session session = MCRHIBConnection.instance().getSession();
String deleteEmptyLabels = "delete from {h-schema}MCRCategoryLabels where text is null or trim(text) = ''";
int affected = session.createNativeQuery(deleteEmptyLabels).executeUpdate();
LOGGER.info("Deleted {} labels.", affected);
String sqlQuery = "select cat.classid,cat.categid from {h-schema}MCRCategory cat left outer join {h-schema}MCRCategoryLabels label on cat.internalid = label.category where label.text is null";
@SuppressWarnings("unchecked") List<Object[]> list = session.createNativeQuery(sqlQuery).getResultList();
for (Object resultList : list) {
Object[] arrayOfResults = (Object[]) resultList;
String classIDString = (String) arrayOfResults[0];
String categIDString = (String) arrayOfResults[1];
MCRCategoryID mcrCategID = new MCRCategoryID(classIDString, categIDString);
MCRLabel mcrCategLabel = new MCRLabel(MCRConstants.DEFAULT_LANG, categIDString, null);
MCRCategoryDAOFactory.getInstance().setLabel(mcrCategID, mcrCategLabel);
LOGGER.info("fixing category with class ID \"{}\" and category ID \"{}\"", classIDString, categIDString);
}
LOGGER.info("Fixing category labels completed!");
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method listAllClassifications.
/**
* List all IDs of all classifications stored in the database
*/
@MCRCommand(syntax = "list all classifications", help = "The command list all classification stored in the database.", order = 100)
public static void listAllClassifications() {
List<MCRCategoryID> allClassIds = DAO.getRootCategoryIDs();
for (MCRCategoryID id : allClassIds) {
LOGGER.info(id.getRootID());
}
LOGGER.info("");
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method listClassification.
/**
* List a MCRClassification.
*
* @param classid
* the MCRObjectID of the classification
*/
@MCRCommand(syntax = "list classification {0}", help = "The command list the classification with MCRObjectID {0}.", order = 90)
public static void listClassification(String classid) {
MCRCategoryID clid = MCRCategoryID.rootID(classid);
MCRCategory cl = DAO.getCategory(clid, -1);
LOGGER.info(classid);
if (cl != null) {
listCategory(cl);
} else {
LOGGER.error("Can't find classification {}", classid);
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRPathXML method getFileXML.
/**
* Returns metadata of the file retrievable by 'path' in XML form.
*
* @param path
* Path to File
* @param attrs
* file attributes of given file
*/
public static Document getFileXML(MCRPath path, BasicFileAttributes attrs) throws IOException {
Element root = new Element("file");
root.setAttribute("uri", path.toUri().toString());
root.setAttribute("ownerID", path.getOwner());
String fileName = path.getFileName().toString();
root.setAttribute("name", fileName);
String absolutePath = path.getOwnerRelativePath();
root.setAttribute("path", absolutePath);
root.setAttribute("extension", getFileExtension(fileName));
root.setAttribute("returnId", MCRMetadataManager.getObjectId(MCRObjectID.getInstance(path.getOwner()), 10, TimeUnit.SECONDS).toString());
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(path));
for (MCRCategoryID category : linksFromReference) {
Element catEl = new Element("category");
catEl.setAttribute("id", category.toString());
root.addContent(catEl);
}
if (!attrs.isDirectory() && attrs instanceof MCRFileAttributes<?>) {
addAttributes(root, (MCRFileAttributes<?>) attrs, path);
} else {
addBasicAttributes(root, attrs, path);
}
return new Document(root);
}
Aggregations