Search in sources :

Example 56 with LogicalData

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

the class JDBCatalogue method getChildrenByParentRef.

public Collection<LogicalData> getChildrenByParentRef(Long parentRef, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT uid, ownerId, datatype, ldName, createDate, modifiedDate, ldLength, " + "contentTypesStr, pdriGroupRef, isSupervised, checksum, lastValidationDate, " + "lockTokenId, lockScope, lockType, lockedByUser, lockDepth, lockTimeout, " + "description, locationPreference, accessDate, ttlSec " + "FROM ldata_table WHERE ldata_table.parentRef = ?")) {
        preparedStatement.setLong(1, parentRef);
        ResultSet rs = preparedStatement.executeQuery();
        LinkedList<LogicalData> res = new LinkedList<>();
        while (rs.next()) {
            LogicalData element = new LogicalData();
            element.setUid(rs.getLong(1));
            element.setParentRef(parentRef);
            element.setOwner(rs.getString(2));
            element.setType(rs.getString(3));
            element.setName(rs.getString(4));
            element.setCreateDate(rs.getTimestamp(5).getTime());
            element.setModifiedDate(rs.getTimestamp(6).getTime());
            element.setLength(rs.getLong(7));
            element.setContentTypesAsString(rs.getString(8));
            element.setPdriGroupId(rs.getLong(9));
            element.setSupervised(rs.getBoolean(10));
            element.setChecksum(rs.getString(11));
            element.setLastValidationDate(rs.getLong(12));
            element.setLockTokenID(rs.getString(13));
            element.setLockScope(rs.getString(14));
            element.setLockType(rs.getString(15));
            element.setLockedByUser(rs.getString(16));
            element.setLockDepth(rs.getString(17));
            element.setLockTimeout(rs.getLong(18));
            element.setDescription(rs.getString(19));
            // element.setDataLocationPreference(rs.getString(20));
            element.setLastAccessDate(rs.getTimestamp(21) != null ? rs.getTimestamp(21).getTime() : null);
            int ttl = rs.getInt(22);
            element.setTtlSec(rs.wasNull() ? null : ttl);
            res.add(element);
        }
        return res;
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData)

Example 57 with LogicalData

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

the class SetBulkPermissionsResource method setPermissionsJava.

private void setPermissionsJava(String rootPath, Permissions perm, MyPrincipal principal, @Nonnull Connection connection) throws SQLException, UnsupportedEncodingException {
    LogicalData ld = catalogue.getLogicalDataByPath(io.milton.common.Path.path(rootPath), connection);
    Permissions p = catalogue.getPermissions(ld.getUid(), ld.getOwner(), connection);
    if (ld.isFolder() && principal.canRead(p)) {
        try (PreparedStatement ps = connection.prepareStatement("SELECT uid, ownerId, datatype FROM ldata_table WHERE parentRef = ?")) {
            setPermissionsJava(ld.getUid(), principal, ps, perm, connection);
        }
    }
    if (principal.canWrite(p)) {
        catalogue.updateOwner(ld.getUid(), perm.getOwner(), connection);
        catalogue.setPermissions(ld.getUid(), perm, connection);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 58 with LogicalData

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

the class StorageSitesService method updateLogicalDataAndPdri.

@PUT
@Path("update_pdri/{uid}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void updateLogicalDataAndPdri(PDRIDescrWrapperList pdris, @PathParam("uid") Long uid) throws SQLException, IOException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection cn = getCatalogue().getConnection()) {
            for (PDRIDescr pdriDescr : pdris.getPdris()) {
                LogicalData logicalData = getCatalogue().getLogicalDataByUid(uid, cn);
                PDRI pdri = PDRIFactory.getFactory().createInstance(pdriDescr, false);
                logicalData.setLength(pdri.getLength());
                getCatalogue().updatePdri(logicalData, pdri, cn);
            }
            cn.commit();
            cn.close();
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) Connection(java.sql.Connection) PDRI(nl.uva.cs.lobcder.resources.PDRI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 59 with LogicalData

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

the class TTL method setTTL.

/**
 * Sets the time to live for a folder
 *
 * @param uid the uid of the folder
 * @param ttl the time to live in sec
 */
@Path("{uid}/{ttl}")
@PUT
public void setTTL(@PathParam("uid") Long uid, @PathParam("ttl") Integer ttl) {
    try {
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        try (Connection cn = getCatalogue().getConnection()) {
            LogicalData ld = getCatalogue().getLogicalDataByUid(uid, cn);
            if (ld == null) {
                throw new WebApplicationException(Response.Status.NOT_FOUND);
            }
            Permissions p = getCatalogue().getPermissions(uid, ld.getOwner(), cn);
            if (!mp.canWrite(p)) {
                throw new WebApplicationException(Response.Status.UNAUTHORIZED);
            }
            getCatalogue().setTTL(uid, ttl, cn);
            cn.commit();
        }
    // try (Connection cn = getCatalogue().getConnection()) {
    // try (PreparedStatement ps = cn.prepareStatement("SELECT uid, ownerId, ttlSec FROM ldata_table WHERE uid=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
    // ps.setLong(1, uid);
    // ResultSet rs = ps.executeQuery();
    // if (!rs.next()) {
    // throw new WebApplicationException(Response.Status.NOT_FOUND);
    // } else {
    // String owner = rs.getString(2);
    // p = getCatalogue().getPermissions(uid, owner, cn);
    // if (!mp.canWrite(p)) {
    // throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    // }
    // rs.updateInt(3, ttl);
    // rs.updateRow();
    // cn.commit();
    // }
    // } catch (SQLException ex) {
    // Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
    // cn.rollback();
    // throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    // }
    // } catch (SQLException ex) {
    // Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
    // }
    // }
    } catch (SQLException ex) {
        Logger.getLogger(TTL.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 60 with LogicalData

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

the class TTL method getDir.

@Path("getdir/{ttl}")
@GET
public String getDir(@PathParam("ttl") Integer ttl) {
    if (PropertiesHelper.getTmpDirUid() == null) {
        throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
    }
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    try (Connection cn = getCatalogue().getConnection()) {
        try {
            LogicalData newFolderEntry = new LogicalData();
            newFolderEntry.setType(Constants.LOGICAL_FOLDER);
            newFolderEntry.setParentRef(PropertiesHelper.getTmpDirUid());
            newFolderEntry.setName(UUID.randomUUID().toString());
            newFolderEntry.setCreateDate(System.currentTimeMillis());
            newFolderEntry.setModifiedDate(System.currentTimeMillis());
            newFolderEntry.setLastAccessDate(System.currentTimeMillis());
            newFolderEntry.setTtlSec(ttl);
            newFolderEntry.setOwner(mp.getUserId());
            getCatalogue().setPermissions(getCatalogue().registerDirLogicalData(newFolderEntry, cn).getUid(), new Permissions(mp, new Permissions()), cn);
            cn.commit();
            return newFolderEntry.getName();
        } catch (Exception ex) {
            cn.rollback();
            Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
    } catch (SQLException sqle) {
        Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, sqle);
        throw new WebApplicationException(sqle, 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) SQLException(java.sql.SQLException)

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