Search in sources :

Example 1 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class AuditServiceImpl method getActivityFeeds.

protected boolean getActivityFeeds(String user, String site, int startPos, int size, String filterType, boolean hideLiveItems, List<ContentItemTO> contentItems, int remainingItem) {
    List<AuditLog> activityFeeds = auditServiceInternal.selectUserFeedEntries(user, site, startPos, size, filterType, hideLiveItems);
    boolean hasMoreItems = true;
    // if number of items returned is less than size it means that table has no more records
    if (activityFeeds.size() < size) {
        hasMoreItems = false;
    }
    if (activityFeeds != null && activityFeeds.size() > 0) {
        for (int index = 0; index < activityFeeds.size() && remainingItem != 0; index++) {
            AuditLog auditLog = activityFeeds.get(index);
            String id = auditLog.getPrimaryTargetValue();
            ContentItemTO item = createActivityItem(site, auditLog, id);
            contentItems.add(item);
            remainingItem--;
        }
    }
    logger.debug("Total Item post live filter : " + contentItems.size() + " hasMoreItems : " + hasMoreItems);
    return hasMoreItems;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 2 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO 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 3 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class ContentServiceImpl method loadContentTypeProperties.

protected void loadContentTypeProperties(String site, ContentItemTO item, String contentType) {
    // TODO: SJ: Refactor in 2.7.x
    if (item.isFolder()) {
        item.setContentType(CONTENT_TYPE_FOLDER);
    } else {
        if (contentType != null && !contentType.equals(CONTENT_TYPE_FOLDER) && !contentType.equals("asset") && !contentType.equals(CONTENT_TYPE_UNKNOWN)) {
            ContentTypeConfigTO config = servicesConfig.getContentTypeConfig(site, contentType);
            if (config != null) {
                item.setForm(config.getForm());
                item.setFormPagePath(config.getFormPath());
                item.setPreviewable(config.isPreviewable());
                item.isPreviewable = item.previewable;
            }
        } else {
            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
            String mimeType = mimeTypesMap.getContentType(item.getName());
            if (mimeType != null && !StringUtils.isEmpty(mimeType)) {
                item.setPreviewable(ContentUtils.matchesPatterns(mimeType, servicesConfig.getPreviewableMimetypesPaterns(site)));
                item.isPreviewable = item.previewable;
            }
        }
    }
// TODO CodeRev:but what if the config is null?
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO)

Example 4 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class ContentServiceImpl method loadContentItem.

protected ContentItemTO loadContentItem(String site, String path) {
    // TODO: SJ: Refactor such that the populate of non-XML is also a method in 3.1+
    ContentItemTO item = createNewContentItemTO(site, path);
    if (item.uri.endsWith(".xml") && !item.uri.startsWith("/config/")) {
        try {
            item = populateContentDrivenProperties(site, item);
        } catch (Exception err) {
            logger.debug("error constructing item for object at site '{}' path '{}'", err, site, path);
        }
    } else {
        item.setLevelDescriptor(item.name.equals(servicesConfig.getLevelDescriptorName(site)));
        item.page = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getPagePatterns(site));
        item.isPage = item.page;
        item.previewable = item.page;
        item.isPreviewable = item.previewable;
        item.asset = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getAssetPatterns(site)) || ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getRenderingTemplatePatterns(site)) || ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getScriptsPatterns(site));
        item.isAsset = item.asset;
        item.component = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getComponentPatterns(site)) || item.isLevelDescriptor() || item.asset;
        item.isComponent = item.component;
        item.document = ContentUtils.matchesPatterns(item.getUri(), servicesConfig.getDocumentPatterns(site));
        item.isDocument = item.document;
        item.browserUri = item.getUri();
        item.setContentType(getContentTypeClass(site, path));
    }
    loadContentTypeProperties(site, item, item.contentType);
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String mimeType = mimeTypesMap.getContentType(item.getName());
    if (StringUtils.isNotEmpty(mimeType)) {
        item.setMimeType(mimeType);
    }
    return item;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) IOException(java.io.IOException) AuthenticationException(org.craftercms.studio.api.v1.exception.security.AuthenticationException) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) SAXException(org.xml.sax.SAXException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DocumentException(org.dom4j.DocumentException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException)

Example 5 with ContentItemTO

use of org.craftercms.studio.api.v1.to.ContentItemTO in project studio by craftercms.

the class ContentServiceImpl method populateWorkflowProperties.

protected void populateWorkflowProperties(String site, ContentItemTO item) {
    ItemState state = objectStateService.getObjectState(site, item.getUri(), false);
    if (state != null) {
        if (item.isFolder()) {
            boolean liveFolder = objectStateService.isFolderLive(site, item.getUri());
            item.setNew(!liveFolder);
            item.setLive(liveFolder);
        } else {
            item.setNew(State.isNew(State.valueOf(state.getState())));
            item.setLive(State.isLive(State.valueOf(state.getState())));
        }
        item.isNew = item.isNew();
        item.isLive = item.isLive();
        item.setInProgress(!item.isLive());
        item.isInProgress = item.isInProgress();
        item.setScheduled(State.isScheduled(State.valueOf(state.getState())));
        item.isScheduled = item.isScheduled();
        item.setSubmitted(State.isSubmitted(State.valueOf(state.getState())));
        item.isSubmitted = item.isSubmitted();
        item.setInFlight(state.getSystemProcessing() == 1);
        item.isInFlight = item.isInFlight();
    } else {
        if (item.isFolder()) {
            boolean liveFolder = objectStateService.isFolderLive(site, item.getUri());
            item.setNew(!liveFolder);
            item.setLive(liveFolder);
            item.isNew = item.isNew();
            item.isLive = item.isLive();
            item.setInProgress(!item.isLive());
            item.isInProgress = item.isInProgress();
        }
    }
}
Also used : ItemState(org.craftercms.studio.api.v1.dal.ItemState)

Aggregations

ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)60 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)19 HashMap (java.util.HashMap)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)15 ArrayList (java.util.ArrayList)10 ItemState (org.craftercms.studio.api.v1.dal.ItemState)10 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)10 JSONObject (net.sf.json.JSONObject)6 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 HashSet (java.util.HashSet)5 JSONException (net.sf.json.JSONException)5 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)5 ZonedDateTime (java.time.ZonedDateTime)4 CryptoException (org.craftercms.commons.crypto.CryptoException)4 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 DocumentException (org.dom4j.DocumentException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3