Search in sources :

Example 6 with ItemState

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

the class ObjectStateServiceImpl method isUpdatedOrNew.

@Override
@ValidateParams
public boolean isUpdatedOrNew(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) {
    path = FilenameUtils.normalize(path, true);
    ItemState state = getObjectState(site, path);
    if (state != null) {
        return State.isUpdateOrNew(State.valueOf(state.getState()));
    } else {
        return false;
    }
}
Also used : ItemState(org.craftercms.studio.api.v1.dal.ItemState) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 7 with ItemState

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

the class ObjectStateServiceImpl method insertNewEntry.

@Override
@ValidateParams
public void insertNewEntry(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) {
    String itemPath = FilenameUtils.normalize(path, true);
    String lockKey = site + ":" + path;
    generalLockService.lock(lockKey);
    try {
        Map<String, String> params = new HashMap<String, String>();
        params.put("site", site);
        params.put("path", itemPath);
        ItemState state = itemStateMapper.getObjectStateBySiteAndPath(params);
        if (state == null) {
            ItemState newEntry = new ItemState();
            newEntry.setObjectId(UUID.randomUUID().toString());
            newEntry.setSite(site);
            newEntry.setPath(itemPath);
            newEntry.setSystemProcessing(0);
            newEntry.setState(State.NEW_UNPUBLISHED_UNLOCKED.name());
            itemStateMapper.insertEntry(newEntry);
        }
    } finally {
        generalLockService.unlock(lockKey);
    }
}
Also used : HashMap(java.util.HashMap) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 8 with ItemState

use of org.craftercms.studio.api.v1.dal.ItemState 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;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 9 with ItemState

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

the class ObjectStateServiceImpl method isInWorkflow.

@Override
@ValidateParams
public boolean isInWorkflow(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) {
    path = FilenameUtils.normalize(path, true);
    ItemState state = getObjectState(site, path);
    if (state != null) {
        return State.isInWorkflow(State.valueOf(state.getState()));
    } else {
        return false;
    }
}
Also used : ItemState(org.craftercms.studio.api.v1.dal.ItemState) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 10 with ItemState

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

the class ObjectStateServiceImpl method isSubmitted.

@Override
@ValidateParams
public boolean isSubmitted(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path) {
    path = FilenameUtils.normalize(path, true);
    ItemState state = getObjectState(site, path);
    if (state != null) {
        return State.isSubmitted(State.valueOf(state.getState()));
    } else {
        return false;
    }
}
Also used : ItemState(org.craftercms.studio.api.v1.dal.ItemState) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

ItemState (org.craftercms.studio.api.v1.dal.ItemState)25 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)19 HashMap (java.util.HashMap)12 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)7 ArrayList (java.util.ArrayList)5 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)5 State (org.craftercms.studio.api.v1.service.objectstate.State)5 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)3 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)3 InputStream (java.io.InputStream)2 Map (java.util.Map)2 CryptoException (org.craftercms.commons.crypto.CryptoException)2 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)2 PreviewEventContext (org.craftercms.studio.api.v1.ebus.PreviewEventContext)2 DocumentException (org.dom4j.DocumentException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ZonedDateTime (java.time.ZonedDateTime)1