Search in sources :

Example 1 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata in project studio by craftercms.

the class DashboardServiceImpl method preparePublishingResult.

private List<PublishingDashboardItem> preparePublishingResult(List<PublishingHistoryItem> publishingHistory) {
    List<PublishingDashboardItem> publishingDashboardItems = new ArrayList<PublishingDashboardItem>();
    for (PublishingHistoryItem historyItem : publishingHistory) {
        PublishingDashboardItem dashboardItem = new PublishingDashboardItem();
        ItemMetadata itemMetadata = objectMetadataManager.getProperties(historyItem.getSiteId(), historyItem.getPath());
        dashboardItem.setSiteId(historyItem.getSiteId());
        dashboardItem.setPath(historyItem.getPath());
        dashboardItem.setLabel(itemMetadata.getName());
        dashboardItem.setEnvironment(historyItem.getEnvironment());
        dashboardItem.setPublishedDate(historyItem.getPublishedDate());
        dashboardItem.setPublisher(historyItem.getPublisher());
        publishingDashboardItems.add(dashboardItem);
    }
    return publishingDashboardItems;
}
Also used : PublishingDashboardItem(org.craftercms.studio.model.rest.dashboard.PublishingDashboardItem) ArrayList(java.util.ArrayList) PublishingHistoryItem(org.craftercms.studio.api.v2.dal.PublishingHistoryItem) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 2 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata in project studio by craftercms.

the class DashboardServiceImpl method prepareContentDashboardResult.

private List<ContentDashboardItem> prepareContentDashboardResult(List<ItemMetadata> itemMetadataList) {
    List<ContentDashboardItem> contentDashboardItemList = new ArrayList<ContentDashboardItem>();
    if (itemMetadataList != null && itemMetadataList.size() > 0) {
        for (ItemMetadata item : itemMetadataList) {
            ContentDashboardItem contentDashboardItem = new ContentDashboardItem();
            contentDashboardItem.setSiteId(item.getSite());
            contentDashboardItem.setPath(item.getPath());
            contentDashboardItem.setLabel(item.getName());
            contentDashboardItem.setModifier(item.getModifier());
            contentDashboardItem.setModifiedDate(item.getModified());
            contentDashboardItemList.add(contentDashboardItem);
        }
    }
    return contentDashboardItemList;
}
Also used : ArrayList(java.util.ArrayList) ContentDashboardItem(org.craftercms.studio.model.rest.dashboard.ContentDashboardItem) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 3 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata in project studio by craftercms.

the class PublishServiceImpl method preparePublishingResult.

private List<PublishingDashboardItem> preparePublishingResult(List<PublishingHistoryItem> publishingHistory) {
    List<PublishingDashboardItem> publishingDashboardItems = new ArrayList<PublishingDashboardItem>();
    for (PublishingHistoryItem historyItem : publishingHistory) {
        PublishingDashboardItem dashboardItem = new PublishingDashboardItem();
        ItemMetadata itemMetadata = objectMetadataManager.getProperties(historyItem.getSiteId(), historyItem.getPath());
        dashboardItem.setSiteId(historyItem.getSiteId());
        dashboardItem.setPath(historyItem.getPath());
        dashboardItem.setLabel(itemMetadata.getName());
        dashboardItem.setEnvironment(historyItem.getEnvironment());
        dashboardItem.setPublishedDate(historyItem.getPublishedDate());
        dashboardItem.setPublisher(historyItem.getPublisher());
        publishingDashboardItems.add(dashboardItem);
    }
    return publishingDashboardItems;
}
Also used : PublishingDashboardItem(org.craftercms.studio.model.rest.dashboard.PublishingDashboardItem) ArrayList(java.util.ArrayList) PublishingHistoryItem(org.craftercms.studio.api.v2.dal.PublishingHistoryItem) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 4 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata in project studio by craftercms.

the class ContentServiceImpl method populateMetadata.

protected void populateMetadata(String site, ContentItemTO item) {
    // TODO: SJ: Refactor to return a ContentItemTO instead of changing the parameter
    // TODO: SJ: Change method name to be getContentItemMetadata or similar
    // TODO: SJ: 3.1+
    // TODO: SJ: Create a method String getValueIfNotNull(String) to use to return not null/empty string if null
    // TODO: SJ: Use that method to reduce redundant code here. 3.1+
    ItemMetadata metadata = objectMetadataManager.getProperties(site, item.getUri());
    if (metadata != null) {
        // database if it's not null
        if (StringUtils.isEmpty(metadata.getLockOwner())) {
            item.setLockOwner("");
        } else {
            item.setLockOwner(metadata.getLockOwner());
        }
        // Set the scheduled date
        if (metadata.getLaunchDate() != null) {
            item.scheduledDate = metadata.getLaunchDate();
            item.setScheduledDate(metadata.getLaunchDate());
        }
        if (metadata.getPublishedDate() != null) {
            item.published = true;
            item.setPublished(true);
            item.publishedDate = metadata.getPublishedDate();
            item.setPublishedDate(metadata.getPublishedDate());
        }
        // Set the modifier (user) if known
        if (StringUtils.isEmpty(metadata.getModifier())) {
            item.setUser("");
            item.setUserLastName("");
            item.setUserFirstName("");
        } else {
            item.user = metadata.getModifier();
            item.setUser(metadata.getModifier());
            if (StringUtils.isEmpty(metadata.getFirstName())) {
                item.userFirstName = metadata.getModifier();
                item.setUserFirstName(metadata.getModifier());
            } else {
                item.userFirstName = metadata.getFirstName();
                item.setUserFirstName(metadata.getFirstName());
            }
            if (StringUtils.isEmpty(metadata.getLastName())) {
                item.userLastName = "";
                item.setUserLastName("");
            } else {
                item.userLastName = metadata.getLastName();
                item.setUserLastName(metadata.getLastName());
            }
        }
        if (metadata.getModified() != null) {
            item.lastEditDate = metadata.getModified();
            item.eventDate = metadata.getModified();
            item.setLastEditDate(metadata.getModified());
            item.setEventDate(metadata.getModified());
        }
        if (StringUtils.isNotEmpty(metadata.getSubmissionComment())) {
            item.setSubmissionComment(metadata.getSubmissionComment());
        }
        if (StringUtils.isNotEmpty(metadata.getSubmittedToEnvironment())) {
            item.setSubmittedToEnvironment(metadata.getSubmittedToEnvironment());
        }
    } else {
        item.setLockOwner("");
    }
}
Also used : ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 5 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata in project studio by craftercms.

the class ContentServiceImpl method updateDatabaseOnMove.

protected void updateDatabaseOnMove(String site, String fromPath, String movePath) throws SiteNotFoundException {
    logger.debug("updateDatabaseOnMove FROM {0} TO {1}  ", fromPath, movePath);
    String user = securityService.getCurrentUser();
    Map<String, String> params = new HashMap<>();
    params.put(DmConstants.KEY_SOURCE_PATH, fromPath);
    params.put(DmConstants.KEY_TARGET_PATH, movePath);
    // These do not exist in 3.0, note some extensions may be using it
    // params.put(DmConstants.KEY_SOURCE_FULL_PATH, expandRelativeSitePath(site, fromPath));
    // params.put(DmConstants.KEY_TARGET_FULL_PATH, expandRelativeSitePath(site, movePath));
    ContentItemTO renamedItem = getContentItem(site, movePath, 0);
    String contentType = renamedItem.getContentType();
    if (!renamedItem.isFolder()) {
        dmContentLifeCycleService.process(site, user, movePath, contentType, DmContentLifeCycleService.ContentLifeCycleOperation.RENAME, params);
        // change the path of this object in the object state database
        objectStateService.updateObjectPath(site, fromPath, movePath);
        objectStateService.transition(site, renamedItem, SAVE);
        renamedItem = getContentItem(site, movePath, 0);
    }
    // update metadata
    if (!objectMetadataManager.isRenamed(site, fromPath)) {
        // if an item was previously moved, we do not track intermediate moves because it will
        // ultimately orphan deployed content.  Old Path is always the OLDEST DEPLOYED PATH
        ItemMetadata metadata = objectMetadataManager.getProperties(site, fromPath);
        if (metadata == null && !renamedItem.isFolder()) {
            if (!objectMetadataManager.metadataExist(site, fromPath)) {
                objectMetadataManager.insertNewObjectMetadata(site, fromPath);
            }
            metadata = objectMetadataManager.getProperties(site, fromPath);
        }
        if (!renamedItem.isNew() && !renamedItem.isFolder()) {
            // if the item is not new, we need to track the old URL for deployment
            logger.debug("item is not new, and has not previously been moved. Track the old URL {0}", fromPath);
            Map<String, Object> objMetadataProps = new HashMap<String, Object>();
            objMetadataProps.put(ItemMetadata.PROP_RENAMED, 1);
            objMetadataProps.put(ItemMetadata.PROP_OLD_URL, fromPath);
            objectMetadataManager.setObjectMetadata(site, fromPath, objMetadataProps);
        }
    }
    if (!renamedItem.isFolder()) {
        if (objectMetadataManager.metadataExist(site, movePath)) {
            if (!StringUtils.equalsIgnoreCase(fromPath, movePath)) {
                objectMetadataManager.deleteObjectMetadata(site, movePath);
            }
        }
        objectMetadataManager.updateObjectPath(site, fromPath, movePath);
    }
    // write activity stream
    SiteFeed siteFeed = siteService.getSite(site);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_MOVE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(site + ":" + movePath);
    if (renamedItem.isFolder()) {
        auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
    } else {
        auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
    }
    auditLog.setPrimaryTargetValue(movePath);
    auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, movePath));
    auditServiceInternal.insertAuditLog(auditLog);
    updateDependenciesOnMove(site, fromPath, movePath);
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Aggregations

ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)14 ArrayList (java.util.ArrayList)7 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)4 HashMap (java.util.HashMap)3 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)3 FastArrayList (org.apache.commons.collections.FastArrayList)2 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)2 RepositoryItem (org.craftercms.studio.api.v1.repository.RepositoryItem)2 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)2 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)2 PublishingHistoryItem (org.craftercms.studio.api.v2.dal.PublishingHistoryItem)2 PublishingDashboardItem (org.craftercms.studio.model.rest.dashboard.PublishingDashboardItem)2 ZonedDateTime (java.time.ZonedDateTime)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 ItemState (org.craftercms.studio.api.v1.dal.ItemState)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 DependencyRules (org.craftercms.studio.api.v1.service.dependency.DependencyRules)1 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)1 DmDependencyTO (org.craftercms.studio.api.v1.to.DmDependencyTO)1 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)1