From c51998445fc630c66b025181b4b0f22f1cde4bd6 Mon Sep 17 00:00:00 2001 From: Alessandro Pieve Date: Thu, 16 Feb 2017 10:58:36 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/resource-management/quota-library@142593 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 31 +++ .project | 42 ++++ .settings/.jsdtscope | 13 ++ .settings/org.eclipse.core.resources.prefs | 5 + .settings/org.eclipse.jdt.core.prefs | 8 + .settings/org.eclipse.m2e.core.prefs | 4 + .settings/org.eclipse.wst.common.component | 9 + ....eclipse.wst.common.project.facet.core.xml | 7 + ...rg.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + .settings/org.eclipse.wst.validation.prefs | 2 + distro/INSTALL | 1 + distro/LICENSE | 6 + distro/MAINTAINERS | 1 + distro/README | 38 ++++ distro/changelog.xml | 5 + distro/descriptor.xml | 42 ++++ distro/profile.xml | 26 +++ distro/svnpath.txt | 1 + pom.xml | 94 ++++++++ .../management/quota/library/QuotaList.java | 33 +++ .../quota/library/ServicePackages.java | 33 +++ .../quota/library/quotalist/AccessType.java | 14 ++ .../quota/library/quotalist/CallerType.java | 11 + .../quota/library/quotalist/Quota.java | 54 +++++ .../quota/library/quotalist/QuotaType.java | 28 +++ .../library/quotalist/ServicePackage.java | 96 ++++++++ .../quotalist/ServicePackageDetail.java | 85 +++++++ .../quota/library/quotalist/ServiceQuota.java | 213 ++++++++++++++++++ .../quota/library/quotalist/StorageQuota.java | 167 ++++++++++++++ .../quota/library/quotalist/TimeInterval.java | 24 ++ .../library/quotedefault/QuotaDefault.java | 38 ++++ .../quotedefault/QuotaDefaultList.java | 27 +++ .../quotedefault/ServiceQuotaDefault.java | 142 ++++++++++++ .../quotedefault/StorageQuotaDefault.java | 121 ++++++++++ .../library/status/QuotaStorageStatus.java | 68 ++++++ src/main/webapp/WEB-INF/web.xml | 7 + .../library/quote/SerializationTest.java | 67 ++++++ 38 files changed, 1565 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/.jsdtscope create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 .settings/org.eclipse.wst.validation.prefs create mode 100644 distro/INSTALL create mode 100644 distro/LICENSE create mode 100644 distro/MAINTAINERS create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 distro/svnpath.txt create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/resource/management/quota/library/QuotaList.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/ServicePackages.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/AccessType.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/CallerType.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/Quota.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/QuotaType.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackage.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackageDetail.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/ServiceQuota.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/StorageQuota.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotalist/TimeInterval.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefault.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefaultList.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotedefault/ServiceQuotaDefault.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/quotedefault/StorageQuotaDefault.java create mode 100644 src/main/java/org/gcube/resource/management/quota/library/status/QuotaStorageStatus.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/java/org/gcube/resource/management/quota/library/quote/SerializationTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..eed8a51 --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..83b2def --- /dev/null +++ b/.project @@ -0,0 +1,42 @@ + + + quota-library + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..b72a6a4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..839d647 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..443e085 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..cff6057 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..4045d87 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1 @@ + diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..630ba97 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,6 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..a08f4b5 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1 @@ +*Alessandro Pieve (alessandro.pieve@isti.cnr.it), CNR, Italy \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..fb46150 --- /dev/null +++ b/distro/README @@ -0,0 +1,38 @@ +The gCube System - ${name} +---------------------- + +This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2), D4Science (FP7-INFRA-2007-1.2.2), +D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2), and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil). + +Authors +------- + +* Alessandro Pieve (alessandro.pieve@isti.cnr.it), CNR, Italy + +Version and Release Date +------------------------ +${version} + +Description +----------- +${description} + +Download information +-------------------- + +Source code is available from SVN: +${scm.url} + +Binaries can be downloaded from: + + +Documentation +------------- +Documentation is available on-line from the Projects Documentation Wiki: +https://gcube.wiki.gcube-system.org/gcube/index.php/.... + + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..1df49a3 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,5 @@ + + + First Release + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..21d8c88 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,42 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + + + ${distroDirectory}/profile.xml + / + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..91c49e4 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,26 @@ + + + + Service + + ${description} + Common + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..f416f9d --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b6aed0e --- /dev/null +++ b/pom.xml @@ -0,0 +1,94 @@ + + 4.0.0 + org.gcube.resource.management + quota-library + jar + 1.0.0-SNAPSHOT + quota-service Maven Webapp + + maven-parent + org.gcube.tools + 1.0.0 + + + distro + + + + junit + junit + 4.9 + test + + + ch.qos.logback + logback-classic + 1.0.13 + test + + + + + org.gcube.accounting + accounting-analytics + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + + + org.gcube.accounting + accounting-lib + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + diff --git a/src/main/java/org/gcube/resource/management/quota/library/QuotaList.java b/src/main/java/org/gcube/resource/management/quota/library/QuotaList.java new file mode 100644 index 0000000..dfa8ca7 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/QuotaList.java @@ -0,0 +1,33 @@ +package org.gcube.resource.management.quota.library; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.resource.management.quota.library.quotalist.Quota; + +@XmlRootElement(name = "quote") +@XmlAccessorType (XmlAccessType.FIELD) + +public class QuotaList +{ + + @XmlElement(name = "quota") + private List quotaList; + + @SuppressWarnings("unused") + private QuotaList(){} + + public QuotaList(List quotaList) { + super(); + this.quotaList = quotaList; + } + + public List getQuotaList() { + return quotaList; + } + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/ServicePackages.java b/src/main/java/org/gcube/resource/management/quota/library/ServicePackages.java new file mode 100644 index 0000000..db6f50c --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/ServicePackages.java @@ -0,0 +1,33 @@ +package org.gcube.resource.management.quota.library; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.resource.management.quota.library.quotalist.ServicePackage; + + +@XmlRootElement(name = "servicepackages") +@XmlAccessorType (XmlAccessType.FIELD) +public class ServicePackages { + + @XmlElement(name = "servicepackage") + private List servicePackages; + + @SuppressWarnings("unused") + private ServicePackages(){} + + public ServicePackages(List servicePackages) { + super(); + this.servicePackages = servicePackages; + } + + public List getPackages() { + return servicePackages; + } + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/AccessType.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/AccessType.java new file mode 100644 index 0000000..d9a829f --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/AccessType.java @@ -0,0 +1,14 @@ +package org.gcube.resource.management.quota.library.quotalist; + +public enum AccessType { + ALL(0), + ACCESS(1), + DELETE(2), + EXECUTE(3), + WRITE(4); + @SuppressWarnings("unused") + private int value; + private AccessType(int value){ + this.value=value; + } +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/CallerType.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/CallerType.java new file mode 100644 index 0000000..eec4716 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/CallerType.java @@ -0,0 +1,11 @@ +package org.gcube.resource.management.quota.library.quotalist; +public enum CallerType { + USER(1), + ROLE(2), + SERVICE(3); + @SuppressWarnings("unused") + private int value; + private CallerType(int value){ + this.value=value; + } +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/Quota.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/Quota.java new file mode 100644 index 0000000..f3038c8 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/Quota.java @@ -0,0 +1,54 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + + +@XmlRootElement(name = "quota") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlSeeAlso({ServiceQuota.class, StorageQuota.class}) + +public abstract class Quota { + +protected long id; + + protected Quota() {} + + public abstract QuotaType getQuotaType(); + + public abstract String getQuotaAsString(); + + public abstract String getIdentifier(); + + public abstract String getContext(); + + public abstract CallerType getCallerType(); + + public abstract TimeInterval getTimeInterval(); + + public abstract Double getQuotaValue(); + + public abstract Calendar getCreationTime(); + + public abstract Calendar getLastUpdateTime(); + + public abstract void setCreationTime(Calendar creationTime); + + public abstract void setLastUpdateTime(Calendar lastUpdateTime); + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/QuotaType.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/QuotaType.java new file mode 100644 index 0000000..d427bd1 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/QuotaType.java @@ -0,0 +1,28 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; +import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord; + +public enum QuotaType { + + //STORAGE(0,AggregatedStorageUsageRecord.class,"dataVolume"), + STORAGE(0,AggregatedStorageStatusRecord.class,"dataVolume"), + SERVICE(1,AggregatedServiceUsageRecord.class,"operationCount"); + + @SuppressWarnings("unused") + private int value; + private Class> typeclz; + private String checkManager; + private QuotaType(int value,Class> clz,String checkManager){ + this.value=value; + this.typeclz=clz; + this.checkManager=checkManager; + } + public Class> getQuotaTypeClass(){ + return typeclz; + } + public String getCheckManager(){ + return checkManager; + } +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackage.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackage.java new file mode 100644 index 0000000..93316a0 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackage.java @@ -0,0 +1,96 @@ +package org.gcube.resource.management.quota.library.quotalist; + + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "servicepackage") +@XmlAccessorType (XmlAccessType.FIELD) +public class ServicePackage { + + protected long id; + protected String name; + protected List servicesPackagesDetail; + + public ServicePackage() {} + + public ServicePackage(String name,List servicesPackagesDetail) { + super(); + this.name = name; + this.servicesPackagesDetail = servicesPackagesDetail; + } + + + public String getServicePackagesAsString() { + return this.name+","+this.servicesPackagesDetail; + } + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getServicesPackageDetail() { + return servicesPackagesDetail; + } + + public void setPackageDetail(List servicesPackagesDetail) { + this.servicesPackagesDetail = servicesPackagesDetail; + } + + @Override + public String toString() { + return "ServicePackage [id=" + id + ", name=" + name + ", packageDetail=" + + servicesPackagesDetail + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + + ((servicesPackagesDetail == null) ? 0 : servicesPackagesDetail.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServicePackage other = (ServicePackage) obj; + if (id != other.id) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (servicesPackagesDetail == null) { + if (other.servicesPackagesDetail != null) + return false; + } else if (!servicesPackagesDetail.equals(other.servicesPackagesDetail)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackageDetail.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackageDetail.java new file mode 100644 index 0000000..8360133 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServicePackageDetail.java @@ -0,0 +1,85 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "servicepackagedetail") +@XmlAccessorType (XmlAccessType.FIELD) +public class ServicePackageDetail { + + protected long id; + protected long idServicesPackage; + protected String content; + + public ServicePackageDetail() {} + + public ServicePackageDetail(long idServicesPackage,String content) { + super(); + this.idServicesPackage = idServicesPackage; + this.content = content; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIdServicePackage() { + return idServicesPackage; + } + + public void setIdServicesPackage(long idServicesPackage) { + this.idServicesPackage = idServicesPackage; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((content == null) ? 0 : content.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + (int) (idServicesPackage ^ (idServicesPackage >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServicePackageDetail other = (ServicePackageDetail) obj; + if (content == null) { + if (other.content != null) + return false; + } else if (!content.equals(other.content)) + return false; + if (id != other.id) + return false; + if (idServicesPackage != other.idServicesPackage) + return false; + return true; + } + + @Override + public String toString() { + return "ServicePackageDetail [id=" + id + ", idPackage=" + idServicesPackage + + ", content=" + content + "]"; + } + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServiceQuota.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServiceQuota.java new file mode 100644 index 0000000..3d8ceed --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/ServiceQuota.java @@ -0,0 +1,213 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ServiceQuota extends Quota { + + private String context; + private String identifier; + private CallerType callerType; + private TimeInterval timeInterval; + private Double quotaValue; + /* + private Long servicePackageId; + */ + private String serviceId; + private AccessType accessType; + + private Calendar lastUpdateTime; + private Calendar creationTime; + + + protected ServiceQuota(){} + + public ServiceQuota(String context,String identifier,CallerType callerType,TimeInterval timeInterval,Double quotaValue,AccessType accessType) { + super(); + this.context = context; + this.identifier = identifier; + this.callerType=callerType; + this.timeInterval = timeInterval; + this.quotaValue = quotaValue; + this.accessType=accessType; + } + + public ServiceQuota(String context,String identifier,CallerType callerType, String serviceId,TimeInterval timeInterval,Double quotaValue,AccessType accessType) { + super(); + this.context = context; + this.identifier = identifier; + this.callerType=callerType; + this.serviceId=serviceId; + this.timeInterval = timeInterval; + this.quotaValue = quotaValue; + this.accessType= accessType; + } + + @Override + public QuotaType getQuotaType() { + return QuotaType.SERVICE; + } + + @Override + public String getQuotaAsString() { + return this.context+","+this.identifier+","+this.callerType+","+this.serviceId+","+this.timeInterval.toString()+","+this.quotaValue+","+this.accessType; + + } + + public String getContext() { + return context; + } + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + @Override + public CallerType getCallerType() { + return callerType; + } + + public void setCallerType(CallerType callerType) { + this.callerType = callerType; + } + + @Override + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + + public Double getQuotaValue() { + return quotaValue; + } + public void setQuotaValue(Double quotaValue) { + this.quotaValue = quotaValue; + } + + public Calendar getLastUpdateTime() { + return lastUpdateTime; + } + + public Calendar getCreationTime() { + return creationTime; + } + + public void setLastUpdateTime(Calendar lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } + + public void setCreationTime(Calendar creationTime) { + this.creationTime = creationTime; + } + + public String getServiceId() { + return serviceId; + } + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public AccessType getAccessType() { + return accessType; + } + + public void setAccessType(AccessType accessType) { + this.accessType = accessType; + } + + + + @Override + public String toString() { + return "ServiceQuota [context=" + context + ", identifier=" + + identifier + ", callerType=" + callerType + ", timeInterval=" + + timeInterval + ", quotaValue=" + quotaValue + ", serviceId=" + + serviceId + ", accessType=" + accessType + + ", lastUpdateTime=" + lastUpdateTime + ", creationTime=" + + creationTime + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((accessType == null) ? 0 : accessType.hashCode()); + result = prime * result + + ((callerType == null) ? 0 : callerType.hashCode()); + result = prime * result + ((context == null) ? 0 : context.hashCode()); + result = prime * result + + ((creationTime == null) ? 0 : creationTime.hashCode()); + result = prime * result + + ((identifier == null) ? 0 : identifier.hashCode()); + result = prime * result + + ((lastUpdateTime == null) ? 0 : lastUpdateTime.hashCode()); + result = prime * result + + ((quotaValue == null) ? 0 : quotaValue.hashCode()); + result = prime * result + + ((serviceId == null) ? 0 : serviceId.hashCode()); + result = prime * result + + ((timeInterval == null) ? 0 : timeInterval.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceQuota other = (ServiceQuota) obj; + if (accessType != other.accessType) + return false; + if (callerType != other.callerType) + return false; + if (context == null) { + if (other.context != null) + return false; + } else if (!context.equals(other.context)) + return false; + if (creationTime == null) { + if (other.creationTime != null) + return false; + } else if (!creationTime.equals(other.creationTime)) + return false; + if (identifier == null) { + if (other.identifier != null) + return false; + } else if (!identifier.equals(other.identifier)) + return false; + if (lastUpdateTime == null) { + if (other.lastUpdateTime != null) + return false; + } else if (!lastUpdateTime.equals(other.lastUpdateTime)) + return false; + if (quotaValue == null) { + if (other.quotaValue != null) + return false; + } else if (!quotaValue.equals(other.quotaValue)) + return false; + if (serviceId == null) { + if (other.serviceId != null) + return false; + } else if (!serviceId.equals(other.serviceId)) + return false; + if (timeInterval != other.timeInterval) + return false; + return true; + } + + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/StorageQuota.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/StorageQuota.java new file mode 100644 index 0000000..a804906 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/StorageQuota.java @@ -0,0 +1,167 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + + + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class StorageQuota extends Quota { + private String context; + private String identifier; + private CallerType callerType; + private TimeInterval timeInterval; + private Double quotaValue; + + + private Calendar lastUpdateTime; + private Calendar creationTime; + + + protected StorageQuota(){} + + public StorageQuota(String context,String identifier,CallerType callerType, TimeInterval timeInterval,Double quotaValue) { + super(); + this.context = context; + this.identifier = identifier; + this.callerType=callerType; + this.timeInterval = timeInterval; + this.quotaValue = quotaValue; + } + + @Override + public QuotaType getQuotaType() { + return QuotaType.STORAGE; + } + + @Override + public String getQuotaAsString() { + return this.context+","+this.identifier+","+this.callerType+","+this.timeInterval.toString()+","+quotaValue; + + } + + public String getContext() { + return context; + } + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + @Override + public CallerType getCallerType() { + return callerType; + } + + public void setCallerType(CallerType callerType) { + this.callerType = callerType; + } + + @Override + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + + public Double getQuotaValue() { + return quotaValue; + } + public void setQuotaValue(Double quotaValue) { + this.quotaValue = quotaValue; + } + + public Calendar getLastUpdateTime() { + return lastUpdateTime; + } + + public Calendar getCreationTime() { + return creationTime; + } + + public void setLastUpdateTime(Calendar lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } + + public void setCreationTime(Calendar creationTime) { + this.creationTime = creationTime; + } + + @Override + public String toString() { + return "StorageQuota [context=" + context + ", identifier=" + + identifier + ", callerType=" + callerType + ", timeInterval=" + timeInterval + + ", quotaValue=" + quotaValue + ", lastUpdateTime=" + + lastUpdateTime + ", creationTime=" + creationTime + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((callerType == null) ? 0 : callerType.hashCode()); + result = prime * result + ((context == null) ? 0 : context.hashCode()); + result = prime * result + + ((creationTime == null) ? 0 : creationTime.hashCode()); + result = prime * result + + ((identifier == null) ? 0 : identifier.hashCode()); + result = prime * result + + ((lastUpdateTime == null) ? 0 : lastUpdateTime.hashCode()); + result = prime * result + + ((quotaValue == null) ? 0 : quotaValue.hashCode()); + result = prime * result + + ((timeInterval == null) ? 0 : timeInterval.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StorageQuota other = (StorageQuota) obj; + if (callerType != other.callerType) + return false; + if (context == null) { + if (other.context != null) + return false; + } else if (!context.equals(other.context)) + return false; + if (creationTime == null) { + if (other.creationTime != null) + return false; + } else if (!creationTime.equals(other.creationTime)) + return false; + if (identifier == null) { + if (other.identifier != null) + return false; + } else if (!identifier.equals(other.identifier)) + return false; + if (lastUpdateTime == null) { + if (other.lastUpdateTime != null) + return false; + } else if (!lastUpdateTime.equals(other.lastUpdateTime)) + return false; + if (quotaValue == null) { + if (other.quotaValue != null) + return false; + } else if (!quotaValue.equals(other.quotaValue)) + return false; + if (timeInterval != other.timeInterval) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotalist/TimeInterval.java b/src/main/java/org/gcube/resource/management/quota/library/quotalist/TimeInterval.java new file mode 100644 index 0000000..51bc72d --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotalist/TimeInterval.java @@ -0,0 +1,24 @@ +package org.gcube.resource.management.quota.library.quotalist; + +import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode; + + +public enum TimeInterval { + DAILY(1, AggregationMode.DAILY), + MONTHLY(31,AggregationMode.MONTHLY), + YEARLY(365,AggregationMode.YEARLY), + FOREVER(0,null); + private int value; + private AggregationMode mode; + private TimeInterval(int value,AggregationMode mode){ + this.value=value; + this.mode=mode; + } + + public int getValue(){ + return this.value; + } + public AggregationMode getAggregationMode(){ + return this.mode; + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefault.java b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefault.java new file mode 100644 index 0000000..0396c59 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefault.java @@ -0,0 +1,38 @@ +package org.gcube.resource.management.quota.library.quotedefault; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import org.gcube.resource.management.quota.library.quotalist.CallerType; +import org.gcube.resource.management.quota.library.quotalist.QuotaType; +import org.gcube.resource.management.quota.library.quotalist.TimeInterval; + +/** + * + * @author Alessandro Pieve at ISTI-CNR + * (alessandro.pieve@isti.cnr.it) + * ex: + * + * USER + * 1.5 + * DAILY + * + */ + +@XmlRootElement(name = "QuotaDefault") +@XmlSeeAlso({ServiceQuotaDefault.class, StorageQuotaDefault.class}) +public abstract class QuotaDefault { + + protected QuotaDefault() {} + + public abstract QuotaType getQuotaType(); + + public abstract String getQuotaAsString(); + + public abstract CallerType getCallerType(); + + public abstract TimeInterval getTimeInterval(); + + public abstract Double getQuotaValue(); + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefaultList.java b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefaultList.java new file mode 100644 index 0000000..fd22ef4 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/QuotaDefaultList.java @@ -0,0 +1,27 @@ +package org.gcube.resource.management.quota.library.quotedefault; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "QuotaList") +@XmlAccessorType (XmlAccessType.FIELD) +public class QuotaDefaultList +{ + @XmlElementRefs({ + @XmlElementRef(type = StorageQuotaDefault.class), + @XmlElementRef(type = ServiceQuotaDefault.class) + }) + private List quotaList= null; + + public List getQuotaDefaultList() { + return quotaList; + } + public void setQuotaDefaultList(List quotaList) { + this.quotaList = quotaList; + } + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotedefault/ServiceQuotaDefault.java b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/ServiceQuotaDefault.java new file mode 100644 index 0000000..db0237c --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/ServiceQuotaDefault.java @@ -0,0 +1,142 @@ +package org.gcube.resource.management.quota.library.quotedefault; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.resource.management.quota.library.quotalist.AccessType; +import org.gcube.resource.management.quota.library.quotalist.CallerType; +import org.gcube.resource.management.quota.library.quotalist.QuotaType; +import org.gcube.resource.management.quota.library.quotalist.TimeInterval; + + + +/** + * + * @author Alessandro Pieve (alessandro.pieve@isti.cnr.it) + * ex: + * + * USER + * DAILY + * a:b:c + * ALL + * 1.5 + * + */ + +@XmlRootElement(name = "ServiceQuotaDefault") +@XmlAccessorType(XmlAccessType.FIELD) +public class ServiceQuotaDefault extends QuotaDefault { + + private CallerType callerType; + private TimeInterval timeInterval; + private String serviceId; + private AccessType accessType; + private Double quotaValue; + + protected ServiceQuotaDefault(){} + + @Override + public QuotaType getQuotaType() { + return QuotaType.SERVICE; + } + + @Override + public String getQuotaAsString() { + return this.callerType+","+this.serviceId+","+this.timeInterval.toString()+","+this.quotaValue+","+this.accessType; + + } + + @Override + public CallerType getCallerType() { + return callerType; + } + + public void setCallerType(CallerType callerType) { + this.callerType = callerType; + } + + @Override + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + + public Double getQuotaValue() { + return quotaValue; + } + public void setQuotaValue(Double quotaValue) { + this.quotaValue = quotaValue; + } + + public String getServiceId() { + return serviceId; + } + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public AccessType getAccessType() { + return accessType; + } + public void setAccessType(AccessType accessType) { + this.accessType = accessType; + } + + @Override + public String toString() { + return "ServiceQuotaDefault [callerType=" + callerType + + ", timeInterval=" + timeInterval + ", quotaValue=" + + quotaValue + ", serviceId=" + serviceId + ", accessType=" + + accessType + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((accessType == null) ? 0 : accessType.hashCode()); + result = prime * result + + ((callerType == null) ? 0 : callerType.hashCode()); + result = prime * result + + ((quotaValue == null) ? 0 : quotaValue.hashCode()); + result = prime * result + + ((serviceId == null) ? 0 : serviceId.hashCode()); + result = prime * result + + ((timeInterval == null) ? 0 : timeInterval.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceQuotaDefault other = (ServiceQuotaDefault) obj; + if (accessType != other.accessType) + return false; + if (callerType != other.callerType) + return false; + if (quotaValue == null) { + if (other.quotaValue != null) + return false; + } else if (!quotaValue.equals(other.quotaValue)) + return false; + if (serviceId == null) { + if (other.serviceId != null) + return false; + } else if (!serviceId.equals(other.serviceId)) + return false; + if (timeInterval != other.timeInterval) + return false; + return true; + } + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/quotedefault/StorageQuotaDefault.java b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/StorageQuotaDefault.java new file mode 100644 index 0000000..72975ff --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/quotedefault/StorageQuotaDefault.java @@ -0,0 +1,121 @@ +package org.gcube.resource.management.quota.library.quotedefault; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.resource.management.quota.library.quotalist.CallerType; +import org.gcube.resource.management.quota.library.quotalist.QuotaType; +import org.gcube.resource.management.quota.library.quotalist.TimeInterval; + +/** + * + * @author Alessandro Pieve (alessandro.pieve@isti.cnr.it) + * ex: + * + * USER + * DAILY + * 1.5 + * + */ + + +@XmlRootElement(name = "StorageQuotaDefault") +public class StorageQuotaDefault extends QuotaDefault { + + private CallerType callerType; + private TimeInterval timeInterval; + private Double quotaValue; + + protected StorageQuotaDefault(){} + + + public StorageQuotaDefault(CallerType callerType,TimeInterval timeInterval,Double quotaValue){ + this.callerType=callerType; + this.timeInterval=timeInterval; + this.quotaValue=quotaValue; + } + + @Override + + public QuotaType getQuotaType() { + return QuotaType.STORAGE; + } + + @Override + public String getQuotaAsString() { + return this.callerType+","+this.timeInterval.toString()+","+quotaValue; + + } + + @Override + public CallerType getCallerType() { + return callerType; + } + + public void setCallerType(CallerType callerType) { + this.callerType = callerType; + } + + @Override + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + + public Double getQuotaValue() { + return quotaValue; + } + public void setQuotaValue(Double quotaValue) { + this.quotaValue = quotaValue; + } + + @Override + public String toString() { + return "StorageQuotaDefault [callerType=" + callerType + + ", timeInterval=" + timeInterval + ", quotaValue=" + + quotaValue + "]"; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((callerType == null) ? 0 : callerType.hashCode()); + result = prime * result + + ((quotaValue == null) ? 0 : quotaValue.hashCode()); + result = prime * result + + ((timeInterval == null) ? 0 : timeInterval.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StorageQuotaDefault other = (StorageQuotaDefault) obj; + if (callerType != other.callerType) + return false; + if (quotaValue == null) { + if (other.quotaValue != null) + return false; + } else if (!quotaValue.equals(other.quotaValue)) + return false; + if (timeInterval != other.timeInterval) + return false; + return true; + } + + + + + + +} diff --git a/src/main/java/org/gcube/resource/management/quota/library/status/QuotaStorageStatus.java b/src/main/java/org/gcube/resource/management/quota/library/status/QuotaStorageStatus.java new file mode 100644 index 0000000..82c5d30 --- /dev/null +++ b/src/main/java/org/gcube/resource/management/quota/library/status/QuotaStorageStatus.java @@ -0,0 +1,68 @@ +package org.gcube.resource.management.quota.library.status; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.resource.management.quota.library.quotalist.AccessType; +import org.gcube.resource.management.quota.library.quotalist.CallerType; +import org.gcube.resource.management.quota.library.quotalist.TimeInterval; + + +@XmlRootElement(name = "quotaStatus") +@XmlAccessorType(XmlAccessType.FIELD) + +public class QuotaStorageStatus { + + protected QuotaStorageStatus(){} + + + public QuotaStorageStatus(String identifier,TimeInterval timeInterval,Double quotaValue,Double quotaUsage) { + super(); + this.identifier = identifier; + this.timeInterval = timeInterval; + this.quotaValue = quotaValue; + this.quotaUsage=quotaUsage; + } + + private String identifier; + private TimeInterval timeInterval; + private Double quotaValue; + private Double quotaUsage; + public String getIdentifier() { + return identifier; + } + + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + public TimeInterval getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(TimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + public Double getQuotaValue() { + return quotaValue; + } + public void setQuotaValue(Double quotaValue) { + this.quotaValue = quotaValue; + } + public Double getQuotaUsage() { + return quotaUsage; + } + public void setQuotaUsage(Double quotaUsage) { + this.quotaUsage = quotaUsage; + } + + @Override + public String toString() { + return "QuotaStorageStatus [identifier=" + identifier + + ", timeInterval=" + timeInterval + ", quotaValue=" + + quotaValue + ", quotaUsage=" + quotaUsage + "]"; + } + + + +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/src/test/java/org/gcube/resource/management/quota/library/quote/SerializationTest.java b/src/test/java/org/gcube/resource/management/quota/library/quote/SerializationTest.java new file mode 100644 index 0000000..f851f8d --- /dev/null +++ b/src/test/java/org/gcube/resource/management/quota/library/quote/SerializationTest.java @@ -0,0 +1,67 @@ +package org.gcube.resource.management.quota.library.quote; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBContext; + +import org.gcube.resource.management.quota.library.quotalist.CallerType; +import org.gcube.resource.management.quota.library.quotalist.Quota; +import org.gcube.resource.management.quota.library.quotalist.ServicePackage; +import org.gcube.resource.management.quota.library.quotalist.ServicePackageDetail; +import org.gcube.resource.management.quota.library.quotalist.StorageQuota; +import org.gcube.resource.management.quota.library.quotalist.TimeInterval; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SerializationTest { + + static JAXBContext context; + + @BeforeClass + public static void before() throws Exception{ + // context = JAXBContext.newInstance(Quota.class); + } + + @Test + public void serializeQuota() throws Exception{ + context = JAXBContext.newInstance(Quota.class); + String currentContext="/gcube"; + String identifier="alessandro.pieve"; + //ManagerType managerType=ManagerType.STORAGE; + TimeInterval timeInterval=TimeInterval.DAILY; + Double quotaValue=1000.0; + Quota qu= new StorageQuota(currentContext,identifier,CallerType.USER,timeInterval,quotaValue); + StringWriter sw = new StringWriter(); + context.createMarshaller().marshal(qu, sw); + Quota quCopy= (Quota)context.createUnmarshaller().unmarshal(new StringReader(sw.toString())); + System.out.println(quCopy.getQuotaAsString()); + System.out.println(qu.getQuotaAsString()); + Assert.assertEquals(qu, quCopy); + } + + + @Test + public void serializeServicesPackage() throws Exception{ + context = JAXBContext.newInstance(ServicePackage.class); + long idServicesPackage=1; + String content="InformationSystem:IColllector"; + ServicePackageDetail servicePackagesDetail =new ServicePackageDetail(idServicesPackage,content); + List listServicePackagesDetail =new ArrayList(); + listServicePackagesDetail.add(servicePackagesDetail); + ServicePackage servicePackages= new ServicePackage("pacchetto Test",listServicePackagesDetail); + + + + StringWriter sw = new StringWriter(); + context.createMarshaller().marshal(servicePackages, sw); + ServicePackage servicePackagesCopy= (ServicePackage)context.createUnmarshaller().unmarshal(new StringReader(sw.toString())); + System.out.println(servicePackages.getServicePackagesAsString()); + System.out.println(servicePackagesCopy.getServicePackagesAsString()); + Assert.assertEquals(servicePackages, servicePackagesCopy); + } + +}