Search in sources :

Example 11 with RetryingOperation

use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.

the class PublishingManagerImpl method markItemsReady.

@RetryingOperation
@Override
@ValidateParams
public void markItemsReady(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> copyToEnvironmentItems) throws DeploymentException {
    for (PublishRequest item : copyToEnvironmentItems) {
        item.setState(READY_FOR_LIVE);
        publishRequestMapper.updateItemDeploymentState(item);
    }
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 12 with RetryingOperation

use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.

the class PublishingManagerImpl method markItemsProcessing.

@RetryingOperation
@Override
@ValidateParams
public void markItemsProcessing(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> itemsToDeploy) throws DeploymentException {
    for (PublishRequest item : itemsToDeploy) {
        item.setState(PublishRequest.State.PROCESSING);
        publishRequestMapper.updateItemDeploymentState(item);
    }
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 13 with RetryingOperation

use of org.craftercms.studio.api.v2.annotation.RetryingOperation 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);
    }
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 14 with RetryingOperation

use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.

the class ObjectStateServiceImpl method transition.

@RetryingOperation
@Override
@ValidateParams
public void transition(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, TransitionEvent event) {
    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 currentState = itemStateMapper.getObjectStateBySiteAndPath(params);
        State nextState = null;
        if (currentState == null) {
            logger.debug("Preforming transition event " + event.name() + " on object " + lockKey + " without current state");
            switch(event) {
                case SAVE:
                    nextState = State.NEW_UNPUBLISHED_UNLOCKED;
                    break;
                case SAVE_FOR_PREVIEW:
                    nextState = State.NEW_UNPUBLISHED_LOCKED;
                    break;
                default:
                    nextState = State.NEW_UNPUBLISHED_UNLOCKED;
            }
        } else {
            logger.debug("Preforming transition event " + event + " on object " + lockKey + " with " + currentState.getState() + " state");
            State currentStateValue = State.valueOf(currentState.getState());
            nextState = transitionTable[currentStateValue.ordinal()][event.ordinal()];
        }
        if (currentState == null) {
            ItemState newEntry = new ItemState();
            newEntry.setObjectId(UUID.randomUUID().toString());
            newEntry.setSite(site);
            newEntry.setPath(itemPath);
            newEntry.setSystemProcessing(0);
            newEntry.setState(nextState.name());
            itemStateMapper.insertEntry(newEntry);
        } else if (nextState.toString() != currentState.getState() && nextState != State.NOOP) {
            currentState.setState(nextState.name());
            itemStateMapper.setObjectState(currentState);
        } else if (nextState == State.NOOP) {
            logger.warn("Transition not defined for event " + event.name() + " and current state " + currentState.getState() + " [object id: " + currentState.getObjectId() + "]");
        }
    } catch (Exception e) {
        logger.error("Transition not defined for event", e);
    } finally {
        generalLockService.unlock(lockKey);
    }
    logger.debug("Transition finished for " + event.name() + " on object " + lockKey);
}
Also used : HashMap(java.util.HashMap) State(org.craftercms.studio.api.v1.service.objectstate.State) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ItemState(org.craftercms.studio.api.v1.dal.ItemState) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 15 with RetryingOperation

use of org.craftercms.studio.api.v2.annotation.RetryingOperation in project studio by craftercms.

the class ObjectStateServiceImpl method setObjectState.

@RetryingOperation
@Override
@ValidateParams
public String setObjectState(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "state") String state, boolean systemProcessing) {
    path = FilenameUtils.normalize(path, true);
    Map<String, String> params = new HashMap<String, String>();
    params.put("site", site);
    params.put("path", path);
    ItemState objectState = itemStateMapper.getObjectStateBySiteAndPath(params);
    if (objectState == null) {
        insertNewEntry(site, path);
        objectState = itemStateMapper.getObjectStateBySiteAndPath(params);
    }
    objectState.setState(state);
    objectState.setSystemProcessing(systemProcessing ? 1 : 0);
    itemStateMapper.setObjectState(objectState);
    return "Success";
}
Also used : HashMap(java.util.HashMap) ItemState(org.craftercms.studio.api.v1.dal.ItemState) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)18 HashMap (java.util.HashMap)13 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)8 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)7 UserNotFoundException (org.craftercms.studio.api.v1.exception.security.UserNotFoundException)7 User (org.craftercms.studio.api.v2.dal.User)6 PasswordDoesNotMatchException (org.craftercms.studio.api.v1.exception.security.PasswordDoesNotMatchException)5 UserExternallyManagedException (org.craftercms.studio.api.v1.exception.security.UserExternallyManagedException)5 PasswordRequirementsFailedException (org.craftercms.studio.api.v2.exception.PasswordRequirementsFailedException)5 UserAlreadyExistsException (org.craftercms.studio.api.v1.exception.security.UserAlreadyExistsException)4 ArrayList (java.util.ArrayList)3 ItemState (org.craftercms.studio.api.v1.dal.ItemState)3 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)3 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)3 GitRepositoryHelper (org.craftercms.studio.api.v2.utils.GitRepositoryHelper)3 DeleteBranchCommand (org.eclipse.jgit.api.DeleteBranchCommand)3 Git (org.eclipse.jgit.api.Git)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 Repository (org.eclipse.jgit.lib.Repository)3