Search in sources :

Example 61 with LogicalData

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

the class GraphPopulator method getLogicalDataByUid.

public LogicalData getLogicalDataByUid(Long UID, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement ps = connection.prepareStatement("SELECT parentRef, ownerId, datatype, ldName, " + "createDate, modifiedDate, ldLength, contentTypesStr, pdriGroupRef, " + "isSupervised, checksum, lastValidationDate, lockTokenID, lockScope, " + "lockType, lockedByUser, lockDepth, lockTimeout, description, locationPreference, status " + "FROM ldata_table WHERE ldata_table.uid = ?")) {
        ps.setLong(1, UID);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            LogicalData res = new LogicalData();
            res.setUid(UID);
            res.setParentRef(rs.getLong(1));
            res.setOwner(rs.getString(2));
            res.setType(rs.getString(3));
            res.setName(rs.getString(4));
            res.setCreateDate(rs.getTimestamp(5).getTime());
            res.setModifiedDate(rs.getTimestamp(6).getTime());
            res.setLength(rs.getLong(7));
            res.setContentTypesAsString(rs.getString(8));
            res.setPdriGroupId(rs.getLong(9));
            res.setSupervised(rs.getBoolean(10));
            res.setChecksum(rs.getString(11));
            res.setLastValidationDate(rs.getLong(12));
            res.setLockTokenID(rs.getString(13));
            res.setLockScope(rs.getString(14));
            res.setLockType(rs.getString(15));
            res.setLockedByUser(rs.getString(16));
            res.setLockDepth(rs.getString(17));
            res.setLockTimeout(rs.getLong(18));
            res.setDescription(rs.getString(19));
            // res.setDataLocationPreference(rs.getString(20));
            res.setStatus(rs.getString(21));
            return res;
        } else {
            return null;
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 62 with LogicalData

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

the class DRIDataResource method setSupervised.

/**
 * Sets supervised flag for a resource.
 *
 * @param uid the resource's id
 * @param flag the flag
 */
@Path("{uid}/supervised/{flag}/")
@PUT
public void setSupervised(@PathParam("uid") Long uid, @PathParam("flag") Boolean flag) {
    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.setLogicalDataSupervised(uid, flag, 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 63 with LogicalData

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

the class DRIDataResource method getSupervised.

/**
 * Gets supervised flag for a resource.
 *
 * @param uid the resource's id
 * @return the supervised flag for a resource.
 */
@Path("{uid}/supervised/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Boolean> getSupervised(@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<Boolean>(new QName("supervised"), Boolean.class, res.getSupervised());
    } 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 64 with LogicalData

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

the class DRIDataResource method setChecksum.

/**
 * Sets checksum property for an item
 *
 * @param uid the resource's id
 * @param checksum the checksum. This value is not check if it's correct by
 * lobcder
 */
@Path("{uid}/checksum/{checksum}/")
@PUT
public void setChecksum(@PathParam("uid") Long uid, @PathParam("checksum") String checksum) {
    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.setFileChecksum(uid, checksum, 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 65 with LogicalData

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

the class WebDataDirResource method createAndLock.

/**
 * This means to just lock the name Not to create the resource.
 *
 * @param name
 * @param timeout
 * @param lockInfo
 * @return
 * @throws NotAuthorizedException
 */
@Override
public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException {
    try (Connection connection = getCatalogue().getConnection()) {
        Path newPath = Path.path(getPath(), name);
        // If the resource exists
        LogicalData fileLogicalData = getCatalogue().getLogicalDataByPath(newPath, connection);
        if (fileLogicalData != null) {
            throw new PreConditionFailedException(new WebDataFileResource(fileLogicalData, Path.path(getPath(), name), getCatalogue(), authList));
        }
        LockToken lockToken = new LockToken(UUID.randomUUID().toString(), lockInfo, timeout);
        return lockToken;
    } catch (SQLException | PreConditionFailedException ex) {
        Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, ex);
        if (ex instanceof PreConditionFailedException) {
            throw new RuntimeException(ex);
        }
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : Path(io.milton.common.Path) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

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