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