use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.
the class PublishingManagerImpl method markItemsCompleted.
@Override
@ValidateParams
public void markItemsCompleted(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> processedItems) throws DeploymentException {
ZonedDateTime completed = ZonedDateTime.now();
for (PublishRequest item : processedItems) {
item.setState(PublishRequest.State.COMPLETED);
item.setCompletedDate(completed);
retryingOperationFacade.markPublishRequestCompleted(item);
}
}
use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.
the class PublishingManagerImpl method processItem.
@Override
public DeploymentItemTO processItem(PublishRequest item) throws DeploymentException, SiteNotFoundException {
if (item == null) {
throw new DeploymentException("Cannot process item, item is null.");
}
DeploymentItemTO deploymentItem = new DeploymentItemTO();
deploymentItem.setSite(item.getSite());
deploymentItem.setPath(item.getPath());
deploymentItem.setCommitId(item.getCommitId());
deploymentItem.setPackageId(item.getPackageId());
String site = item.getSite();
String path = item.getPath();
String oldPath = item.getOldPath();
String environment = item.getEnvironment();
String action = item.getAction();
String user = item.getUser();
String liveEnvironment = LIVE_ENVIRONMENT;
if (servicesConfig.isStagingEnvironmentEnabled(site)) {
liveEnvironment = servicesConfig.getLiveEnvironment(site);
}
boolean isLive = false;
if (StringUtils.isNotEmpty(liveEnvironment)) {
if (liveEnvironment.equals(environment)) {
isLive = true;
}
} else if (StringUtils.equalsIgnoreCase(LIVE_ENVIRONMENT, item.getEnvironment()) || StringUtils.equalsIgnoreCase(PRODUCTION_ENVIRONMENT, environment)) {
isLive = true;
}
if (StringUtils.equals(action, PublishRequest.Action.DELETE)) {
if (oldPath != null && oldPath.length() > 0) {
contentService.deleteContent(site, oldPath, user);
boolean hasRenamedChildren = false;
if (oldPath.endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
if (contentService.contentExists(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
// TODO: SJ: This bypasses the Content Service, fix
RepositoryItem[] children = contentRepository.getContentChildren(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
if (children.length > 1) {
hasRenamedChildren = true;
}
}
if (!hasRenamedChildren) {
deleteFolder(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
}
}
deploymentItem.setMove(true);
deploymentItem.setOldPath(oldPath);
objectMetadataManager.clearRenamed(site, path);
}
boolean haschildren = false;
if (item.getPath().endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
if (contentService.contentExists(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
// TODO: SJ: This bypasses the Content Service, fix
RepositoryItem[] children = contentRepository.getContentChildren(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
if (children.length > 1) {
haschildren = true;
}
}
}
if (contentService.contentExists(site, path)) {
contentService.deleteContent(site, path, user);
if (!haschildren) {
deleteFolder(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
}
}
deploymentItem.setDelete(true);
} else {
if (StringUtils.equals(action, PublishRequest.Action.MOVE)) {
deploymentItem.setMove(true);
deploymentItem.setOldPath(oldPath);
if (oldPath != null && oldPath.length() > 0) {
if (isLive) {
objectMetadataManager.clearRenamed(site, path);
}
}
}
ItemMetadata itemMetadata = objectMetadataManager.getProperties(site, path);
if (itemMetadata == null) {
if (contentService.contentExists(site, path)) {
LOGGER.warn("Content item: '" + site + "':'" + path + "' doesn't exists in " + "the database, but does exist in git. This may cause problems " + "in the environment: '" + environment + "'");
} else {
LOGGER.warn("Content item: '" + site + "':'" + path + "' cannot be published. " + "Content does not exist in git nor in the database. Skipping...");
return null;
}
} else {
ContentItemTO contentItem = contentService.getContentItem(site, path);
if (isLive) {
// should consider what should be done if this does not work.
// Currently the method will bail and the item is stuck in processing.
LOGGER.debug("Environment is live, transition item to LIVE state {0}:{1}", site, path);
// check if commit id from workflow and from object state match
if (Objects.isNull(itemMetadata.getCommitId()) || itemMetadata.getCommitId().equals(item.getCommitId())) {
objectStateService.transition(site, contentItem, TransitionEvent.DEPLOYMENT);
}
} else {
objectStateService.transition(site, contentItem, TransitionEvent.SAVE);
}
itemMetadata.setSubmittedBy(StringUtils.EMPTY);
itemMetadata.setSendEmail(0);
itemMetadata.setSubmittedForDeletion(0);
itemMetadata.setSubmissionComment(StringUtils.EMPTY);
itemMetadata.setSubmittedToEnvironment(StringUtils.EMPTY);
itemMetadata.setLaunchDate(null);
objectMetadataManager.updateObjectMetadata(itemMetadata);
}
String blacklistConfig = studioConfiguration.getProperty(CONFIGURATION_PUBLISHING_BLACKLIST_REGEX);
if (StringUtils.isNotEmpty(blacklistConfig) && ContentUtils.matchesPatterns(item.getPath(), Arrays.asList(StringUtils.split(blacklistConfig, ",")))) {
LOGGER.debug("File " + item.getPath() + " of the site " + site + " will not be published because it " + "matches the configured publishing blacklist regex patterns.");
markItemsCompleted(site, item.getEnvironment(), Arrays.asList(item));
deploymentItem = null;
}
}
return deploymentItem;
}
use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.
the class PublishingManagerImpl method markItemsBlocked.
@RetryingOperation
@Override
@ValidateParams
public void markItemsBlocked(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> copyToEnvironmentItems) throws DeploymentException {
for (PublishRequest item : copyToEnvironmentItems) {
item.setState(PublishRequest.State.BLOCKED);
publishRequestMapper.updateItemDeploymentState(item);
}
}
Aggregations