Search in sources :

Example 16 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class AuthenticationsImpl method deleteTicket.

@Override
public void deleteTicket(String me, Parameters parameters, WithResponse withResponse) {
    if (!People.DEFAULT_USER.equals(me)) {
        throw new InvalidArgumentException("Invalid parameter: " + me);
    }
    final String ticket = getTicket(parameters);
    try {
        final String ticketUser = ticketComponent.validateTicket(ticket);
        final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
        // or the user is not fully authenticated
        if (currentUser == null || !currentUser.equals(ticketUser)) {
            throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
        } else {
            // delete the ticket
            authenticationService.invalidateTicket(ticket);
        }
    } catch (AuthenticationException e) {
        throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException)

Example 17 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class AuthenticationsImpl method validateTicket.

@Override
public LoginTicketResponse validateTicket(String me, Parameters parameters, WithResponse withResponse) {
    if (!People.DEFAULT_USER.equals(me)) {
        throw new InvalidArgumentException("Invalid parameter: " + me);
    }
    final String ticket = getTicket(parameters);
    try {
        final String ticketUser = ticketComponent.validateTicket(ticket);
        final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
        // or the user is not fully authenticated
        if (currentUser == null || !currentUser.equals(ticketUser)) {
            throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
        }
    } catch (AuthenticationException e) {
        throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
    }
    LoginTicketResponse response = new LoginTicketResponse();
    response.setId(ticket);
    return response;
}
Also used : LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException)

Example 18 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method removeFavouriteSite.

public void removeFavouriteSite(String personId, String siteId) {
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    siteId = siteInfo.getShortName();
    StringBuilder prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX);
    prefKey.append(siteId);
    String value = (String) preferenceService.getPreference(personId, prefKey.toString());
    boolean isFavouriteSite = (value != null && value.equalsIgnoreCase("true"));
    if (!isFavouriteSite) {
        throw new NotFoundException("Site " + siteId + " is not a favourite site");
    }
    preferenceService.clearPreferences(personId, prefKey.toString());
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 19 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class TagsImpl method changeTag.

public Tag changeTag(StoreRef storeRef, String tagId, Tag tag) {
    try {
        NodeRef existingTagNodeRef = validateTag(storeRef, tagId);
        String existingTagName = taggingService.getTagName(existingTagNodeRef);
        String newTagName = tag.getTag();
        NodeRef newTagNodeRef = taggingService.changeTag(storeRef, existingTagName, newTagName);
        return new Tag(newTagNodeRef, newTagName);
    } catch (NonExistentTagException e) {
        throw new NotFoundException(e.getMessage());
    } catch (TagExistsException e) {
        throw new ConstraintViolatedException(e.getMessage());
    } catch (TaggingException e) {
        throw new InvalidArgumentException(e.getMessage());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) TagExistsException(org.alfresco.repo.tagging.TagExistsException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) TaggingException(org.alfresco.repo.tagging.TaggingException) Tag(org.alfresco.rest.api.model.Tag) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NonExistentTagException(org.alfresco.repo.tagging.NonExistentTagException)

Example 20 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method findVersionIfApplicable.

private NodeRef findVersionIfApplicable(NodeRef nodeRef, String versionLabelId) {
    if (versionLabelId != null) {
        nodeRef = nodes.validateOrLookupNode(nodeRef.getId(), null);
        VersionHistory vh = versionService.getVersionHistory(nodeRef);
        if (vh != null) {
            try {
                Version v = vh.getVersion(versionLabelId);
                nodeRef = VersionUtil.convertNodeRef(v.getFrozenStateNodeRef());
            } catch (VersionDoesNotExistException vdne) {
                throw new NotFoundException("Couldn't find version: [" + nodeRef.getId() + ", " + versionLabelId + "]");
            }
        }
    }
    return nodeRef;
}
Also used : VersionDoesNotExistException(org.alfresco.service.cmr.version.VersionDoesNotExistException) Version(org.alfresco.service.cmr.version.Version) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Aggregations

NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)24 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)11 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)8 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)6 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)4 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)4 StaleEntityException (org.alfresco.rest.framework.core.exceptions.StaleEntityException)4 ContentData (org.alfresco.service.cmr.repository.ContentData)4 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 QName (org.alfresco.service.namespace.QName)3 Test (org.junit.Test)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 RenditionDefinition2 (org.alfresco.repo.rendition2.RenditionDefinition2)2