Search in sources :

Example 26 with MCRCategoryID

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);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 27 with MCRCategoryID

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!");
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Session(org.hibernate.Session) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 28 with MCRCategoryID

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("");
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 29 with MCRCategoryID

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);
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 30 with MCRCategoryID

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);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4