Search in sources :

Example 1 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class StorageSitesService method delete.

@Path("delete/")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void delete(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
    StorageSiteWrapperList sitesWL = jbSites.getValue();
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (sitesWL != null && sitesWL.getSites() != null && sitesWL.getSites().size() > 0 && mp.isAdmin()) {
        List<Long> ids = new ArrayList<>();
        for (StorageSiteWrapper ssw : sitesWL.getSites()) {
            ids.add(ssw.getStorageSiteId());
        // if(ssw.isSaveFilesOnDelete()){
        // getCatalogue().getPdriStorageSiteID(ssw.getStorageSiteId(), null);
        // }
        }
        try (Connection connection = getCatalogue().getConnection()) {
            getCatalogue().deleteStorageSites(ids, connection);
            connection.commit();
        }
    }
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class StorageSitesService method set.

@Path("set/")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void set(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection connection = getCatalogue().getConnection()) {
            StorageSiteWrapperList sitesWL = jbSites.getValue();
            List<StorageSiteWrapper> sswl = sitesWL.getSites();
            if (sswl != null && sswl.size() > 0) {
                Collection<StorageSite> sites = new ArrayList<>();
                for (StorageSiteWrapper ssw : sswl) {
                    StorageSite site = new StorageSite();
                    Credential cred = new Credential();
                    cred.setStorageSitePassword(ssw.getCredential().getStorageSitePassword());
                    cred.setStorageSiteUsername(ssw.getCredential().getStorageSiteUsername());
                    site.setCredential(cred);
                    site.setCurrentNum(ssw.getCurrentNum());
                    site.setCurrentSize(ssw.getCurrentSize());
                    site.setResourceURI(ssw.getResourceURI());
                    site.setEncrypt(ssw.isEncrypt());
                    site.setCache(ssw.isCache());
                    site.setQuotaNum(ssw.getQuotaNum());
                    site.setQuotaSize(ssw.getQuotaSize());
                    sites.add(site);
                }
                getCatalogue().insertOrUpdateStorageSites(sites, connection);
                connection.commit();
            }
        }
    }
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class StorageSitesService method queryStorageSites.

private List<StorageSiteWrapper> queryStorageSites(@Nonnull Connection cn) throws SQLException {
    MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
    List<String> ids = queryParameters.get("id");
    if (ids != null && ids.size() > 0 && ids.get(0).equals("all")) {
        Collection<StorageSite> sites = getCatalogue().getStorageSites(cn, Boolean.FALSE);
        Collection<StorageSite> cachesites = getCatalogue().getStorageSites(cn, Boolean.TRUE);
        List<StorageSiteWrapper> sitesWarpper = new ArrayList<>();
        for (StorageSite s : sites) {
            StorageSiteWrapper sw = new StorageSiteWrapper();
            CredentialWrapped cw = new CredentialWrapped();
            cw.setStorageSitePassword(s.getCredential().getStorageSitePassword());
            // cw.setStorageSitePassword("************");
            cw.setStorageSiteUsername(s.getCredential().getStorageSiteUsername());
            sw.setCredential(cw);
            sw.setCurrentNum(s.getCurrentNum());
            sw.setEncrypt(s.isEncrypt());
            sw.setQuotaNum(s.getQuotaNum());
            sw.setQuotaSize(s.getQuotaSize());
            sw.setResourceURI(s.getResourceURI());
            sw.setStorageSiteId(s.getStorageSiteId());
            sw.setCache(false);
            sw.setCurrentSize(s.getCurrentSize());
            sitesWarpper.add(sw);
        }
        for (StorageSite s : cachesites) {
            StorageSiteWrapper sw = new StorageSiteWrapper();
            CredentialWrapped cw = new CredentialWrapped();
            cw.setStorageSitePassword(s.getCredential().getStorageSitePassword());
            // cw.setStorageSitePassword("************");
            cw.setStorageSiteUsername(s.getCredential().getStorageSiteUsername());
            sw.setCredential(cw);
            sw.setCurrentNum(s.getCurrentNum());
            sw.setEncrypt(s.isEncrypt());
            sw.setQuotaNum(s.getQuotaNum());
            sw.setQuotaSize(s.getQuotaSize());
            sw.setResourceURI(s.getResourceURI());
            sw.setStorageSiteId(s.getStorageSiteId());
            sw.setCache(true);
            sw.setCurrentSize(s.getCurrentSize());
            sitesWarpper.add(sw);
        }
        return sitesWarpper;
    }
    return null;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) ArrayList(java.util.ArrayList) CredentialWrapped(nl.uva.cs.lobcder.rest.wrappers.CredentialWrapped)

Example 4 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class StorageSitesService method getXml.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public StorageSiteWrapperList getXml() throws FileNotFoundException, VlException, URISyntaxException, IOException, MalformedURLException, Exception {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection cn = getCatalogue().getConnection()) {
            List<StorageSiteWrapper> res = queryStorageSites(cn, mp.isAdmin());
            StorageSiteWrapperList sswl = new StorageSiteWrapperList();
            sswl.setSites(res);
            return sswl;
        } catch (SQLException ex) {
            Logger.getLogger(StorageSitesService.class.getName()).log(Level.SEVERE, null, ex);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
    return null;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class StorageSitesService method queryStorageSites.

// 
// @Path("set/")
// @PUT
// @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
// public void set(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
// MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
// if (mp.isAdmin()) {
// try (Connection connection = getCatalogue().getConnection()) {
// StorageSiteWrapperList sitesWL = jbSites.getValue();
// List<StorageSiteWrapper> sswl = sitesWL.getSites();
// if (sswl != null && sswl.size() > 0) {
// Collection<StorageSite> sites = new ArrayList<>();
// for (StorageSiteWrapper ssw : sswl) {
// StorageSite site = new StorageSite();
// Credential cred = new Credential();
// cred.setStorageSitePassword(ssw.getCredential().getStorageSitePassword());
// cred.setStorageSiteUsername(ssw.getCredential().getStorageSiteUsername());
// site.setCredential(cred);
// site.setCurrentNum(ssw.getCurrentNum());
// site.setCurrentSize(ssw.getCurrentSize());
// site.setResourceURI(ssw.getResourceURI());
// site.setEncrypt(ssw.isEncrypt());
// site.setCache(ssw.isCache());
// site.setQuotaNum(ssw.getQuotaNum());
// site.setQuotaSize(ssw.getQuotaSize());
// sites.add(site);
// }
// getCatalogue().insertOrUpdateStorageSites(sites, connection, mp.isAdmin());
// connection.commit();
// }
// 
// }
// }
// }
// 
// @Path("delete/")
// @PUT
// @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
// public void delete(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
// StorageSiteWrapperList sitesWL = jbSites.getValue();
// MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
// if (sitesWL != null && sitesWL.getSites() != null && sitesWL.getSites().size() > 0 && mp.isAdmin()) {
// List<Long> ids = new ArrayList<>();
// for (StorageSiteWrapper ssw : sitesWL.getSites()) {
// ids.add(ssw.getStorageSiteId());
// //                if(ssw.isSaveFilesOnDelete()){
// //                    getCatalogue().getPdriStorageSiteID(ssw.getStorageSiteId(), null);
// //                }
// }
// try (Connection connection = getCatalogue().getConnection()) {
// getCatalogue().deleteStorageSites(ids, connection);
// connection.commit();
// }
// }
// }
// 
private List<StorageSiteWrapper> queryStorageSites(@Nonnull Connection cn, Boolean includePrivate) throws SQLException {
    MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
    List<String> ids = queryParameters.get("id");
    if (ids != null && ids.size() > 0 && ids.get(0).equals("all")) {
        Collection<StorageSite> sites = getCatalogue().getStorageSites(cn, Boolean.FALSE, includePrivate);
        Collection<StorageSite> cachesites = getCatalogue().getStorageSites(cn, Boolean.TRUE, includePrivate);
        List<StorageSiteWrapper> sitesWarpper = new ArrayList<>();
        for (StorageSite s : sites) {
            StorageSiteWrapper sw = new StorageSiteWrapper();
            CredentialWrapped cw = new CredentialWrapped();
            cw.setStorageSitePassword(s.getCredential().getStorageSitePassword());
            // cw.setStorageSitePassword("************");
            cw.setStorageSiteUsername(s.getCredential().getStorageSiteUsername());
            sw.setCredential(cw);
            sw.setCurrentNum(s.getCurrentNum());
            sw.setEncrypt(s.isEncrypt());
            sw.setQuotaNum(s.getQuotaNum());
            sw.setQuotaSize(s.getQuotaSize());
            sw.setResourceURI(s.getResourceURI());
            sw.setStorageSiteId(s.getStorageSiteId());
            sw.setIsCache(false);
            sw.setCurrentSize(s.getCurrentSize());
            sitesWarpper.add(sw);
        }
        for (StorageSite s : cachesites) {
            StorageSiteWrapper sw = new StorageSiteWrapper();
            CredentialWrapped cw = new CredentialWrapped();
            cw.setStorageSitePassword(s.getCredential().getStorageSitePassword());
            // cw.setStorageSitePassword("************");
            cw.setStorageSiteUsername(s.getCredential().getStorageSiteUsername());
            sw.setCredential(cw);
            sw.setCurrentNum(s.getCurrentNum());
            sw.setEncrypt(s.isEncrypt());
            sw.setQuotaNum(s.getQuotaNum());
            sw.setQuotaSize(s.getQuotaSize());
            sw.setResourceURI(s.getResourceURI());
            sw.setStorageSiteId(s.getStorageSiteId());
            sw.setIsCache(true);
            sw.setCurrentSize(s.getCurrentSize());
            sitesWarpper.add(sw);
        }
        return sitesWarpper;
    }
    return null;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) ArrayList(java.util.ArrayList) CredentialWrapped(nl.uva.cs.lobcder.rest.wrappers.CredentialWrapped)

Aggregations

StorageSiteWrapper (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper)8 ArrayList (java.util.ArrayList)6 StorageSiteWrapperList (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList)4 Connection (java.sql.Connection)3 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)3 StorageSite (nl.uva.cs.lobcder.resources.StorageSite)3 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 CredentialWrapped (nl.uva.cs.lobcder.rest.wrappers.CredentialWrapped)2 WebResource (com.sun.jersey.api.client.WebResource)1 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 BigInteger (java.math.BigInteger)1 SocketException (java.net.SocketException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 CertificateException (java.security.cert.CertificateException)1 SQLException (java.sql.SQLException)1