Search in sources :

Example 21 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class DRIDataResource method getLastValidationDateDate.

/**
 * Gets lastvalidationdate property for a resource in text format
 *
 * @param uid the resource's id
 * @return the date last validated in text format
 */
@Path("{uid}/lastValidationDate/")
@GET
@Produces({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML })
public String getLastValidationDateDate(@PathParam("uid") Long uid) {
    try (Connection cn = catalogue.getConnection()) {
        LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
        if (res == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
        if (!mp.canRead(p)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
        return new Date(res.getLastValidationDate() * 1000).toString();
    } catch (SQLException ex) {
        Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions) Date(java.util.Date)

Example 22 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class DRIDataResource method setLastValidationDate.

/**
 * Sets lastvalidationdate property for a resource
 *
 * @param uid the resource's id
 * @param lastValidationDate the date last validated
 */
@Path("{uid}/lastValidationDate/{lastValidationDate}/")
@PUT
public void setLastValidationDate(@PathParam("uid") Long uid, @PathParam("lastValidationDate") Long lastValidationDate) {
    try (Connection cn = catalogue.getConnection()) {
        try {
            LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
            if (res == null) {
                throw new WebApplicationException(Response.Status.NOT_FOUND);
            }
            MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
            Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
            if (!mp.canWrite(p)) {
                throw new WebApplicationException(Response.Status.UNAUTHORIZED);
            }
            catalogue.setLastValidationDate(uid, lastValidationDate, cn);
            cn.commit();
        } catch (SQLException ex) {
            Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
            cn.rollback();
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    } catch (SQLException ex) {
        Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 23 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class DRIDataResource method getLastValidationDate.

/**
 * Gets lastvalidationdate property for a resource
 *
 * @param uid the resource's id
 * @return the date last validated
 */
@Path("{uid}/lastValidationDate/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Long> getLastValidationDate(@PathParam("uid") Long uid) {
    try (Connection cn = catalogue.getConnection()) {
        LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
        if (res == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
        if (!mp.canRead(p)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
        return new JAXBElement<Long>(new QName("lastValidationDate"), Long.class, res.getLastValidationDate());
    } catch (SQLException ex) {
        Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions) JAXBElement(javax.xml.bind.JAXBElement)

Example 24 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class DRIDataResource method getChecksum.

/**
 * Gets checksum property for an item.
 *
 * @param uid the resource's id
 * @return the checksum. This value is not check if it's correct by lobcder
 */
@Path("{uid}/checksum/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<String> getChecksum(@PathParam("uid") Long uid) {
    try (Connection cn = catalogue.getConnection()) {
        LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
        if (res == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
        if (!mp.canRead(p)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
        return new JAXBElement<String>(new QName("checksum"), String.class, res.getChecksum());
    } catch (SQLException ex) {
        Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions) JAXBElement(javax.xml.bind.JAXBElement)

Example 25 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class DRItemsResource method setSupervised.

/**
 * Sets supervised flag for a resource.
 *
 * @param flag the flag
 * @param path the resource's path
 */
@Path("supervised/{flag}")
@PUT
public void setSupervised(@PathParam("flag") Boolean flag, @QueryParam("path") String path) throws UnsupportedEncodingException {
    try (Connection cn = catalogue.getConnection()) {
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        if (mp.isAdmin()) {
            try {
                LogicalData logicalData;
                if (path == null || path.isEmpty()) {
                    logicalData = catalogue.getLogicalDataByUid(1L, cn);
                } else {
                    logicalData = catalogue.getLogicalDataByPath(io.milton.common.Path.path(path), cn);
                }
                catalogue.setLogicalDataSupervised(logicalData.getUid(), flag, cn);
                if (logicalData.isFolder()) {
                    try (PreparedStatement ps1 = cn.prepareStatement("UPDATE ldata_table SET isSupervised=? WHERE parentRef = ?");
                        PreparedStatement ps2 = cn.prepareStatement("SELECT uid FROM ldata_table WHERE parentRef = ? AND datatype = '" + Constants.LOGICAL_FOLDER + "'")) {
                        setDirSupervised(logicalData.getUid(), flag, ps1, ps2);
                    }
                }
                cn.commit();
            } catch (SQLException e) {
                Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
                cn.rollback();
            }
        } else {
            Logger.getLogger(DRItemsResource.class.getName()).log(Level.WARNING, "NOT a superuser: want change DRI flag for {0}", path);
        }
    } catch (SQLException e) {
        Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

LogicalData (nl.uva.cs.lobcder.resources.LogicalData)71 Connection (java.sql.Connection)29 SQLException (java.sql.SQLException)29 Permissions (nl.uva.cs.lobcder.auth.Permissions)29 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)20 PreparedStatement (java.sql.PreparedStatement)11 ResultSet (java.sql.ResultSet)10 Path (io.milton.common.Path)7 ArrayList (java.util.ArrayList)7 BadRequestException (io.milton.http.exceptions.BadRequestException)6 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)5 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)5 ConflictException (io.milton.http.exceptions.ConflictException)4 URISyntaxException (java.net.URISyntaxException)4 Stack (java.util.Stack)4 Path (javax.ws.rs.Path)4 LogicalDataWrapped (nl.uva.cs.lobcder.rest.wrappers.LogicalDataWrapped)4 VRL (nl.uva.vlet.vrl.VRL)4 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3