use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class WorkflowServiceImpl method reject.
@Override
@SuppressWarnings("unchecked")
@ValidateParams
public ResultTO reject(@ValidateStringParam(name = "site") String site, String request) throws ServiceLayerException {
ResultTO result = new ResultTO();
try {
String approver = securityService.getCurrentUser();
JSONObject requestObject = JSONObject.fromObject(request);
String reason = (requestObject.containsKey(JSON_KEY_REASON)) ? requestObject.getString(JSON_KEY_REASON) : "";
JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
String scheduledDate = null;
if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
scheduledDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
}
int length = items.size();
if (length > 0) {
SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
for (int index = 0; index < length; index++) {
String stringItem = items.optString(index);
// JSONObject item = items.getJSONObject(index);
// getSubmittedItem(site, item, format, scheduledDate);
DmDependencyTO submittedItem = null;
submittedItem = getSubmittedItem(site, stringItem, format, scheduledDate, null);
submittedItems.add(submittedItem);
}
List<String> paths = new ArrayList<String>();
List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
for (DmDependencyTO goLiveItem : submittedItems) {
if (contentService.contentExists(site, goLiveItem.getUri())) {
paths.add(goLiveItem.getUri());
}
AuditLogParameter auditLogParameter = new AuditLogParameter();
auditLogParameter.setTargetId(site + ":" + goLiveItem.getUri());
auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLogParameter.setTargetValue(goLiveItem.getUri());
auditLogParameters.add(auditLogParameter);
}
objectStateService.setSystemProcessingBulk(site, paths, true);
Set<String> cancelPaths = new HashSet<String>();
cancelPaths.addAll(paths);
deploymentService.cancelWorkflowBulk(site, cancelPaths);
reject(site, submittedItems, reason, approver);
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_REJECT);
auditLog.setActorId(approver);
auditLog.setSiteId(siteFeed.getId());
auditLog.setPrimaryTargetId(site);
auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
auditLog.setPrimaryTargetValue(site);
auditLog.setParameters(auditLogParameters);
auditServiceInternal.insertAuditLog(auditLog);
objectStateService.setSystemProcessingBulk(site, paths, false);
result.setSuccess(true);
result.setStatus(200);
result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, NotificationService.COMPLETE_REJECT, Locale.ENGLISH));
} else {
result.setSuccess(false);
result.setMessage("No items provided for preparation.");
}
} catch (JSONException | DeploymentException e) {
result.setSuccess(false);
result.setMessage(e.getMessage());
}
return result;
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class BlobAwareContentRepository method publish.
@Override
public void publish(String site, String sandboxBranch, List<DeploymentItemTO> deploymentItems, String environment, String author, String comment) throws DeploymentException {
logger.debug("Publishing items {0} to environment {1} in site {2}", deploymentItems, environment, site);
Map<String, StudioBlobStore> stores = new LinkedHashMap<>();
MultiValueMap<String, DeploymentItemTO> items = new LinkedMultiValueMap<>();
List<DeploymentItemTO> localItems = new LinkedList<>();
try {
for (DeploymentItemTO item : deploymentItems) {
StudioBlobStore store = getBlobStore(site, item.getPath());
if (store != null) {
stores.putIfAbsent(store.getId(), store);
items.add(store.getId(), item);
localItems.add(mapDeploymentItem(item));
} else {
localItems.add(item);
}
}
for (String storeId : stores.keySet()) {
logger.debug("Publishing blobs to environment {0} using store {1} for site {2}", environment, storeId, site);
stores.get(storeId).publish(site, sandboxBranch, items.get(storeId), environment, author, comment);
}
logger.debug("Publishing local files to environment {0} for site {1}", environment, site);
localRepositoryV2.publish(site, sandboxBranch, localItems, environment, author, comment);
} catch (Exception e) {
throw new DeploymentException("Error during deployment to environment " + environment + " for site " + site, e);
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class StudioPublisherTask method processPublishingRequest.
private void processPublishingRequest(String siteId, String environment, PublishRequest item, List<DeploymentItemTO> completeDeploymentItemList, Set<String> processedPaths) throws ServiceLayerException, DeploymentException {
List<DeploymentItemTO> missingDependencies = new ArrayList<DeploymentItemTO>();
Set<String> missingDependenciesPaths = new HashSet<String>();
String statusMessage;
try {
List<DeploymentItemTO> deploymentItemList = new ArrayList<DeploymentItemTO>();
logger.debug("Processing [{0}] content item for site \"{1}\"", item.getPath(), siteId);
DeploymentItemTO deploymentItem = publishingManager.processItem(item);
if (deploymentItem != null) {
deploymentItemList.add(deploymentItem);
}
logger.debug("Processing COMPLETE [{0}] content item for site \"{1}\"", item.getPath(), siteId);
if (isMandatoryDependenciesCheckEnabled()) {
logger.debug("Processing Mandatory Deps [{0}] content item for site " + "\"{1}\"", item.getPath(), siteId);
missingDependencies.addAll(publishingManager.processMandatoryDependencies(item, processedPaths, missingDependenciesPaths));
logger.debug("Processing Mandatory Dependencies COMPLETE [{0}]" + " content item for site \"{1}\"", item.getPath(), siteId);
}
deploymentItemList.addAll(missingDependencies);
completeDeploymentItemList.addAll(deploymentItemList);
} catch (DeploymentException err) {
logger.error("Error while executing deployment to environment store for site \"{0}\",", err, siteId);
publishingManager.markItemsReady(siteId, environment, Arrays.asList(item));
siteService.enablePublishing(siteId, false);
statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_ERROR);
siteService.updatePublishingStatusMessage(siteId, ERROR, statusMessage);
throw err;
} catch (Exception err) {
logger.error("Unexpected error while executing deployment to environment " + "store for site \"{0}\", ", err, siteId);
publishingManager.markItemsReady(siteId, environment, Arrays.asList(item));
siteService.enablePublishing(siteId, false);
statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_ERROR);
siteService.updatePublishingStatusMessage(siteId, ERROR, statusMessage);
throw err;
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class DeploymentServiceImpl method deploy.
@Override
@ValidateParams
public void deploy(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<String> paths, ZonedDateTime scheduledDate, @ValidateStringParam(name = "approver") String approver, @ValidateStringParam(name = "submissionComment") String submissionComment, final boolean scheduleDateNow) throws DeploymentException {
if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
objectStateService.transitionBulk(site, paths, SUBMIT_WITHOUT_WORKFLOW_SCHEDULED, NEW_SUBMITTED_NO_WF_SCHEDULED);
}
List<String> newPaths = new ArrayList<String>();
List<String> updatedPaths = new ArrayList<String>();
List<String> movedPaths = new ArrayList<String>();
Map<String, List<String>> groupedPaths = new HashMap<String, List<String>>();
for (String p : paths) {
boolean isFolder = contentRepository.isFolder(site, p);
if (isFolder) {
logger.debug("Content item at path " + p + " for site " + site + " is folder and will not be added to publishing queue.");
} else {
if (objectStateService.isNew(site, p)) {
newPaths.add(p);
} else if (objectMetadataManager.isRenamed(site, p)) {
movedPaths.add(p);
} else {
updatedPaths.add(p);
}
}
}
groupedPaths.put(PublishRequest.Action.NEW, newPaths);
groupedPaths.put(PublishRequest.Action.MOVE, movedPaths);
groupedPaths.put(PublishRequest.Action.UPDATE, updatedPaths);
List<PublishRequest> items = createItems(site, environment, groupedPaths, scheduledDate, approver, submissionComment);
for (PublishRequest item : items) {
publishRequestMapper.insertItemForDeployment(item);
}
objectStateService.setSystemProcessingBulk(site, paths, false);
// We need to pick up this on Inserting , not on execution!
try {
sendContentApprovalEmail(items, scheduleDateNow);
} catch (Exception errNotify) {
logger.error("Error sending approval notification ", errNotify);
}
String statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_QUEUED);
try {
siteService.updatePublishingStatusMessage(site, QUEUED, statusMessage);
} catch (SiteNotFoundException e) {
logger.error("Error updating publishing status for site " + site);
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class DeploymentServiceImpl method delete.
@Override
@ValidateParams
public void delete(@ValidateStringParam(name = "site") String site, List<String> paths, @ValidateStringParam(name = "approver") String approver, ZonedDateTime scheduledDate, String submissionComment) throws DeploymentException, SiteNotFoundException {
if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
objectStateService.transitionBulk(site, paths, DELETE, NEW_DELETED);
}
Set<String> environments = getAllPublishedEnvironments(site);
for (String environment : environments) {
List<PublishRequest> items = createDeleteItems(site, environment, paths, approver, scheduledDate, submissionComment);
for (PublishRequest item : items) {
publishRequestMapper.insertItemForDeployment(item);
}
}
objectStateService.setSystemProcessingBulk(site, paths, false);
String statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_QUEUED);
try {
siteService.updatePublishingStatusMessage(site, QUEUED, statusMessage);
} catch (SiteNotFoundException e) {
logger.error("Error updating publishing status for site " + site);
}
}
Aggregations