use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList 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();
}
}
}
use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList 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();
}
}
}
}
use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList 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;
}
use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList in project lobcder by skoulouzis.
the class Catalogue method getStorageSites.
private List<StorageSiteWrapper> getStorageSites(String id) throws URISyntaxException, UnknownHostException, SocketException, IOException {
if (restClient == null) {
restClient = Client.create(clientConfig);
restClient.removeAllFilters();
restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter("worker-", token));
webResource = restClient.resource(restURL);
}
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("id", id);
WebResource res = webResource.path("storage_sites").queryParams(params);
StorageSiteWrapperList storageSiteList = res.accept(MediaType.APPLICATION_XML).get(new GenericType<StorageSiteWrapperList>() {
});
List<StorageSiteWrapper> ssites = removeUnreachableStorageSites(storageSiteList);
for (StorageSiteWrapper ssw : ssites) {
storageSiteCache.put(ssw.getStorageSiteId(), ssw);
}
return ssites;
}
Aggregations