Search in sources :

Example 16 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class WorkflowServiceImpl method getWorkflowAffectedItems.

protected List<ContentItemTO> getWorkflowAffectedItems(String site, List<String> paths) {
    List<ContentItemTO> items = new ArrayList<>();
    for (String path : paths) {
        ContentItemTO item = contentService.getContentItem(site, path);
        items.add(item);
    }
    return items;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ArrayList(java.util.ArrayList)

Example 17 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class WorkflowServiceImpl method _reject.

protected void _reject(String site, DmDependencyTO dmDependencyTO, String approver, boolean sendEmail, String reason) {
    boolean contentExists = contentService.contentExists(site, dmDependencyTO.getUri());
    if (contentExists) {
        if (!objectMetadataManager.metadataExist(site, dmDependencyTO.getUri())) {
            objectMetadataManager.insertNewObjectMetadata(site, dmDependencyTO.getUri());
        }
        Map<String, Object> newProps = new HashMap<String, Object>();
        newProps.put(ItemMetadata.PROP_SUBMITTED_BY, "");
        newProps.put(ItemMetadata.PROP_SEND_EMAIL, 0);
        newProps.put(ItemMetadata.PROP_SUBMITTED_FOR_DELETION, 0);
        newProps.put(ItemMetadata.PROP_LAUNCH_DATE, null);
        newProps.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, StringUtils.EMPTY);
        objectMetadataManager.setObjectMetadata(site, dmDependencyTO.getUri(), newProps);
        ContentItemTO item = contentService.getContentItem(site, dmDependencyTO.getUri());
        objectStateService.transition(site, item, TransitionEvent.REJECT);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) JSONObject(net.sf.json.JSONObject)

Example 18 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class WorkflowServiceImpl method getInProgressItems.

protected List<ContentItemTO> getInProgressItems(final String site, final DmContentItemComparator comparator, final boolean inProgressOnly) throws ServiceLayerException {
    final List<ContentItemTO> categoryItems = new ArrayList<>();
    List<ContentItemTO> categoryItems1 = getCategoryItems(site);
    categoryItems.addAll(categoryItems1);
    long st = System.currentTimeMillis();
    List<ItemState> changeSet = objectStateService.getChangeSet(site);
    logger.debug("Time taken listChangedAll()  " + (System.currentTimeMillis() - st));
    // the category item to add all other items that do not belong to
    // regular categories specified in the configuration
    st = System.currentTimeMillis();
    if (changeSet != null) {
        List<String> displayPatterns = servicesConfig.getDisplayInWidgetPathPatterns(site);
        // List<String> inProgressItems = new FastList<String>();
        for (ItemState state : changeSet) {
            if (contentService.contentExists(state.getSite(), state.getPath())) {
                if (ContentUtils.matchesPatterns(state.getPath(), displayPatterns)) {
                    ContentItemTO item = contentService.getContentItem(state.getSite(), state.getPath(), 0);
                    addInProgressItems(site, item, categoryItems, comparator, inProgressOnly);
                }
            }
        }
    }
    logger.debug("Time taken after listChangedAll() : " + (System.currentTimeMillis() - st));
    return categoryItems;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ArrayList(java.util.ArrayList)

Example 19 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class ImportServiceImpl method writeContent.

/**
 * write content
 *
 * @param site
 * @param importedPaths
 * @param importedFullPaths
 * @param fileRoot
 * @param parentPath
 * @param name
 * @param overWrite
 */
protected void writeContent(String site, Set<String> importedPaths, List<String> importedFullPaths, String fileRoot, String targetRoot, String parentPath, String name, boolean overWrite) {
    boolean isXml = true;
    String processChain = getXmlChainName();
    if (!name.endsWith(".xml")) {
        isXml = false;
        processChain = getAssetChainName();
    }
    InputStream in = null;
    String filePath = parentPath + FILE_SEPARATOR + name;
    String fileSystemPath = fileRoot + FILE_SEPARATOR + name;
    logger.info("[IMPORT] writeContent: fileRoot [" + fileRoot + "] fullPath [" + filePath + "] overwrite[" + overWrite + "] process chain [ " + processChain + "]");
    long startTimeWrite = System.currentTimeMillis();
    logger.debug("[IMPORT] writing file: " + parentPath + FILE_SEPARATOR + name);
    try {
        File file = new File(fileSystemPath);
        if (file.exists()) {
            in = new FileInputStream(file);
            String currentPath = parentPath + FILE_SEPARATOR + name;
            boolean contentExists = contentService.contentExists(site, currentPath);
            // create parameters
            Map<String, String> params = createParams(site, isXml, targetRoot, parentPath, name);
            String id = site + ":" + filePath + ":" + name;
            // existing
            if (!contentExists || overWrite) {
                String fullPath = targetRoot + filePath;
                objectStateService.setSystemProcessing(site, currentPath, true);
                // write the content
                contentService.processContent(id, in, isXml, params, processChain);
                ContentItemTO item = contentService.getContentItem(site, currentPath);
                // update state
                if (item != null) {
                    objectStateService.transition(site, item, TransitionEvent.SAVE);
                    objectStateService.setSystemProcessing(site, currentPath, false);
                } else {
                    ItemState state = objectStateService.getObjectState(site, currentPath);
                    if (state == null) {
                        objectStateService.insertNewEntry(site, currentPath);
                    }
                }
                importedPaths.add(filePath);
                importedFullPaths.add(fullPath);
            } else {
                logger.debug("[IMPORT] " + filePath + " exists and set to not to overrwite. skipping this file.");
            }
        }
    } catch (FileNotFoundException e) {
        logger.warn("[IMPORT] " + filePath + " does not exist.");
    } catch (ServiceLayerException e) {
        logger.error("[IMPORT] failed to import " + filePath, e);
    } finally {
        ContentUtils.release(in);
    }
    logger.debug("[IMPORT] done writing file: " + parentPath + FILE_SEPARATOR + name + ", time: " + (System.currentTimeMillis() - startTimeWrite));
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ItemState(org.craftercms.studio.api.v1.dal.ItemState) FileNotFoundException(java.io.FileNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 20 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class DependencyServiceImpl method getContentTypeFilteredDeleteDependencies.

private Set<String> getContentTypeFilteredDeleteDependencies(String site, Set<String> paths) {
    Set<String> toRet = new HashSet<String>();
    List<String> deps = getItemDependenciesFromDB(site, paths);
    for (String dep : deps) {
        ContentItemTO item = contentService.getContentItem(site, dep, 0);
        List<DeleteDependencyConfigTO> deleteDependencyConfigList = servicesConfig.getDeleteDependencyPatterns(site, item.getContentType());
        if (CollectionUtils.isNotEmpty(deleteDependencyConfigList)) {
            for (DeleteDependencyConfigTO deleteDependencyConfig : deleteDependencyConfigList) {
                if (dep.matches(deleteDependencyConfig.getPattern())) {
                    toRet.add(dep);
                    break;
                }
            }
        }
    }
    return toRet;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DeleteDependencyConfigTO(org.craftercms.studio.api.v1.to.DeleteDependencyConfigTO) HashSet(java.util.HashSet)

Aggregations

ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)60 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)19 HashMap (java.util.HashMap)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)15 ArrayList (java.util.ArrayList)10 ItemState (org.craftercms.studio.api.v1.dal.ItemState)10 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)10 JSONObject (net.sf.json.JSONObject)6 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 HashSet (java.util.HashSet)5 JSONException (net.sf.json.JSONException)5 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)5 ZonedDateTime (java.time.ZonedDateTime)4 CryptoException (org.craftercms.commons.crypto.CryptoException)4 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 DocumentException (org.dom4j.DocumentException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3