use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ObjectStateServiceImpl method insertNewEntry.
@Override
@ValidateParams
public void insertNewEntry(@ValidateStringParam(name = "site") String site, ContentItemTO item) {
String path = FilenameUtils.normalize(item.getUri(), true);
String lockKey = site + ":" + path;
generalLockService.lock(lockKey);
try {
Map<String, String> params = new HashMap<String, String>();
params.put("site", site);
params.put("path", path);
ItemState state = itemStateMapper.getObjectStateBySiteAndPath(params);
if (state == null) {
ItemState newEntry = new ItemState();
if (StringUtils.isEmpty(item.getNodeRef())) {
newEntry.setObjectId(UUID.randomUUID().toString());
} else {
newEntry.setObjectId(item.getNodeRef());
}
newEntry.setSite(site);
newEntry.setPath(path);
newEntry.setSystemProcessing(0);
newEntry.setState(State.NEW_UNPUBLISHED_UNLOCKED.name());
itemStateMapper.insertEntry(newEntry);
}
} finally {
generalLockService.unlock(lockKey);
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class ObjectStateServiceImpl method getObjectState.
@Override
@ValidateParams
public ItemState getObjectState(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, boolean insert) {
String cleanPath = FilenameUtils.normalize(path, true);
String lockId = site + ":" + cleanPath;
ItemState state = null;
Map<String, String> params = new HashMap<String, String>();
params.put("site", site);
params.put("path", cleanPath);
state = itemStateMapper.getObjectStateBySiteAndPath(params);
if (state == null && insert) {
if (contentService.contentExists(site, cleanPath)) {
ContentItemTO item = contentService.getContentItem(site, cleanPath, 0);
if (!item.isFolder()) {
insertNewEntry(site, item);
state = itemStateMapper.getObjectStateBySiteAndPath(params);
}
}
}
return state;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class DeploymentServiceImpl method createDeleteItems.
private List<PublishRequest> createDeleteItems(String site, String environment, List<String> paths, String approver, ZonedDateTime scheduledDate, String submissionComment) throws SiteNotFoundException {
List<PublishRequest> newItems = new ArrayList<PublishRequest>(paths.size());
String packageId = UUID.randomUUID().toString();
for (String path : paths) {
if (contentService.contentExists(site, path)) {
ContentItemTO contentItem = contentService.getContentItem(site, path, 0);
if (!contentItem.isFolder()) {
PublishRequest item = new PublishRequest();
ItemMetadata metadata = objectMetadataManager.getProperties(site, path);
item.setId(++CTED_AUTOINCREMENT);
item.setSite(site);
item.setEnvironment(environment);
item.setPath(path);
item.setScheduledDate(scheduledDate);
item.setState(PublishRequest.State.READY_FOR_LIVE);
item.setAction(PublishRequest.Action.DELETE);
if (metadata != null) {
if (metadata.getRenamed() > 0) {
String oldPath = metadata.getOldUrl();
item.setOldPath(oldPath);
}
String commitId = metadata.getCommitId();
if (StringUtils.isNotEmpty(commitId) && contentRepositoryV2.commitIdExists(site, commitId)) {
item.setCommitId(commitId);
} else {
if (StringUtils.isNotEmpty(commitId)) {
logger.warn("Commit ID is NULL for content " + path + ". Was the git repo reset at some point?");
} else {
logger.warn("Commit ID " + commitId + " does not exist for content " + path + ". Was the git repo reset at some point?");
}
logger.info("Publishing content from HEAD for " + path);
item.setCommitId(contentRepository.getRepoLastCommitId(site));
}
}
String contentTypeClass = contentService.getContentTypeClass(site, path);
item.setContentTypeClass(contentTypeClass);
item.setUser(approver);
item.setPackageId(packageId);
item.setSubmissionComment(submissionComment);
newItems.add(item);
if (contentService.contentExists(site, path)) {
contentService.deleteContent(site, path, approver);
if (path.endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
deleteFolder(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), approver);
}
}
String lastRepoCommitId = contentRepository.getRepoLastCommitId(site);
if (StringUtils.isNotEmpty(lastRepoCommitId)) {
item.setCommitId(lastRepoCommitId);
}
} else {
RepositoryItem[] children = contentRepository.getContentChildren(site, path);
List<String> childPaths = new ArrayList<String>();
for (RepositoryItem child : children) {
childPaths.add(child.path + FILE_SEPARATOR + child.name);
}
newItems.addAll(createDeleteItems(site, environment, childPaths, approver, scheduledDate, submissionComment));
deleteFolder(site, path, approver);
}
}
}
return newItems;
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class DeploymentServiceImpl method addToScheduledDateList.
/**
* add the given node to the scheduled items list
*
* @param site
* @param launchDate
* @param format
* @param scheduledItems
* @param comparator
* @param subComparator
* @param displayPatterns
* @throws ServiceLayerException
*/
protected void addToScheduledDateList(String site, String environment, ZonedDateTime launchDate, String path, String packageId, List<ContentItemTO> scheduledItems, DmContentItemComparator comparator, DmContentItemComparator subComparator, List<String> displayPatterns) throws ServiceLayerException {
String timeZone = servicesConfig.getDefaultTimezone(site);
String dateLabel = launchDate.withZoneSameInstant(ZoneId.of(timeZone)).format(ISO_OFFSET_DATE_TIME);
// display only if the path matches one of display patterns
if (ContentUtils.matchesPatterns(path, displayPatterns)) {
ContentItemTO itemToAdd = contentService.getContentItem(site, path, 0);
itemToAdd.scheduledDate = launchDate;
itemToAdd.environment = environment;
itemToAdd.packageId = packageId;
boolean found = false;
for (int index = 0; index < scheduledItems.size(); index++) {
ContentItemTO currDateItem = scheduledItems.get(index);
// it non-recursively
if (currDateItem.name.equals(dateLabel)) {
currDateItem.addChild(itemToAdd, subComparator, false);
found = true;
break;
// if the date is after the current date, add a new
// date item before it
// and add the content item to the new date item
} else if (itemToAdd.scheduledDate.compareTo(currDateItem.scheduledDate) < 0) {
ContentItemTO dateItem = createDateItem(dateLabel, itemToAdd, comparator, timeZone);
scheduledItems.add(index, dateItem);
found = true;
break;
}
}
// if not found, add to the end of list
if (!found) {
ContentItemTO dateItem = createDateItem(dateLabel, itemToAdd, comparator, timeZone);
scheduledItems.add(dateItem);
}
}
}
use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.
the class DeploymentServiceImpl method getDeployedItem.
/**
* get a deployed item by the given path. If the item is new, it will be added to the itemsMap
*
* @param site
* @param path
* @return deployed item
*/
protected ContentItemTO getDeployedItem(String site, String path) {
ContentItemTO item = null;
if (!contentService.contentExists(site, path)) {
item = contentService.createDummyDmContentItemForDeletedNode(site, path);
item.setLockOwner("");
} else {
item = contentService.getContentItem(site, path, 0);
}
return item;
}
Aggregations