Search in sources :

Example 11 with ConflictException

use of io.milton.http.exceptions.ConflictException in project lobcder by skoulouzis.

the class CopyJsonResource method processForm.

public String processForm(Map<String, String> parameters, Map<String, FileItem> files) throws BadRequestException, NotAuthorizedException {
    String dest = parameters.get("destination");
    Path pDest = Path.path(dest);
    Resource rDestParent = resourceFactory.getResource(host, pDest.getParent().toString());
    if (rDestParent == null)
        throw new BadRequestException(wrapped, "The destination parent does not exist");
    if (rDestParent instanceof CollectionResource) {
        CollectionResource colDestParent = (CollectionResource) rDestParent;
        if (colDestParent.child(pDest.getName()) == null) {
            try {
                wrapped.copyTo(colDestParent, pDest.getName());
            } catch (ConflictException ex) {
                log.warn("Exception copying to: " + pDest.getName(), ex);
                throw new BadRequestException(rDestParent, "conflict: " + ex.getMessage());
            }
            return null;
        } else {
            log.warn("destination already exists: " + pDest.getName());
            throw new BadRequestException(rDestParent, "File already exists");
        }
    } else {
        throw new BadRequestException(wrapped, "The destination parent is not a collection resource");
    }
}
Also used : Path(io.milton.common.Path) CollectionResource(io.milton.resource.CollectionResource) ConflictException(io.milton.http.exceptions.ConflictException) CopyableResource(io.milton.resource.CopyableResource) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) PostableResource(io.milton.resource.PostableResource) BadRequestException(io.milton.http.exceptions.BadRequestException)

Aggregations

ConflictException (io.milton.http.exceptions.ConflictException)11 BadRequestException (io.milton.http.exceptions.BadRequestException)9 Resource (io.milton.resource.Resource)6 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)5 IOException (java.io.IOException)5 CollectionResource (io.milton.resource.CollectionResource)4 PostableResource (io.milton.resource.PostableResource)4 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 Path (io.milton.common.Path)3 DeletableResource (io.milton.resource.DeletableResource)3 PutableResource (io.milton.resource.PutableResource)3 ReplaceableResource (io.milton.resource.ReplaceableResource)3 NotFoundException (io.milton.http.exceptions.NotFoundException)2 MoveableResource (io.milton.resource.MoveableResource)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 Permissions (nl.uva.cs.lobcder.auth.Permissions)2 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)2