Skip to content

Commit

Permalink
Finished major model revision.
Browse files Browse the repository at this point in the history
Finished model validation capability
  • Loading branch information
jorgearj committed Apr 10, 2014
1 parent 1cbfb89 commit d707ca9
Show file tree
Hide file tree
Showing 15 changed files with 708 additions and 368 deletions.
3 changes: 2 additions & 1 deletion SPIN_API/src/exceptions/ErrorEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum ErrorEnum {
OFFERING_WITHOUT_SERVICE("ServiceOffering \"{0}\" has no included Services. At least one Service must be included."),
OFFERING_WITHOUT_PRICEPLAN("ServiceOffering \"{0}\" has no PricePlan defined. A PricePlan must be defined."),
PRICEPLAN_WITHOUT_COMPONENTS("PricePlan \"{0}\" has no PriceComponent defined. At least one PriceComponent must be defined."),
COMPONENT_WITHOUT_PRICE("PriceComponent \"{0}\" has no mean to calculate its price. It must have either a PriceSpecification or a PriceFunction");
COMPONENT_WITHOUT_PRICE("PriceComponent \"{0}\" has no mean to calculate its price. It must have either a PriceSpecification or a PriceFunction"),
VARIABLE_WITHOUT_VALUE("PriceVariable \"{0}\" has no value assigned. A PriceVariable of the type {1} must have a value.");

private String message;

Expand Down
2 changes: 2 additions & 0 deletions SPIN_API/src/usdl/constants/enums/GREnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum GREnum {
QUANT_PROD_OR_SERV ("quantitativeProductOrServiceProperty", "P"),
BUSINESS_ENTITY ("BusinessEntity", "C"),
PRICE_SPEC ("PriceSpecification", "C"),
QUANT_VALUE ("QuantitativeValue", "C"),
QUAL_VALUE ("QuantitativeValue", "C"),
VALUE_ADDED_TAX_INCLUDED ("valueAddedTaxIncluded", "P"),
HAS_CURRENCY ("hasCurrency","P"),
HAS_CURRENCY_VALUE ("hasCurrencyValue","P"),
Expand Down
6 changes: 5 additions & 1 deletion SPIN_API/src/usdl/constants/enums/ResourceNameEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public enum ResourceNameEnum {
PRICECOMPONENT("Price Component"),
PRICEFUNCTION("Price Function"),
PRICESPEC("Price Specification"),
QUANTVALUE("Quantitative Value");
QUANTVALUE("Quantitative Value"),
QUALVALUE("Qualitative Value"),
CLOUDPROVIDER("Business Entity"),
USAGE("Usage Variable"),
PROVIDER("Provider Variable");

private String name;

Expand Down
2 changes: 2 additions & 0 deletions SPIN_API/src/usdl/constants/enums/USDLPriceEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum USDLPriceEnum {
PRICE_COMPONENT ("PriceComponent", "C"),
DEDUCTION ("Deduction", "C"),
PRICE_FUNCTION ("PriceFunction", "C"),
USAGE("Usage", "C"),
PROVIDER("Constant", "C"),
HAS_PRICE_PLAN ("hasPricePlan", "P"),
HAS_PRICE_COMPONENT ("hasPriceComponent", "P"),
HAS_PRICE_CAP ("hasPriceCap", "P"),
Expand Down
129 changes: 93 additions & 36 deletions SPIN_API/src/usdl/servicemodel/CloudProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@
import java.util.List;

import usdl.constants.enums.FOAFEnum;
import usdl.constants.enums.Prefixes;
import usdl.constants.enums.GREnum;
import usdl.constants.enums.RDFEnum;
import usdl.constants.enums.RDFSEnum;
import usdl.constants.enums.ResourceNameEnum;
import usdl.constants.enums.USDLCoreEnum;
import usdl.constants.properties.PricingAPIProperties;
import usdl.servicemodel.validations.LinkedUSDLValidator;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;

import exceptions.ErrorEnum;
import exceptions.InvalidLinkedUSDLModelException;

public class CloudProvider {
private String name;
private String comment;
private String homepage;
private List<Service> providedServices;
private String localName = null;
private String namespace = null;
private final String resourceType = ResourceNameEnum.OFFERING.getResourceType();


public CloudProvider() {
super();
public CloudProvider(){
this(ResourceNameEnum.CLOUDPROVIDER.getResourceName(), null);
}

public CloudProvider(String name){
this(name, null);
}

public CloudProvider(String name, String nameSpace) {
providedServices = new ArrayList<Service>();
this.setName(name);
this.namespace = nameSpace;
}

public CloudProvider(CloudProvider source) {//copy constructor
Expand Down Expand Up @@ -50,7 +69,12 @@ public String getName() {


public void setName(String name) {
this.name = name;
if(name != null && !name.equalsIgnoreCase("")){
this.name = name;
}else{
this.name = ResourceNameEnum.CLOUDPROVIDER.getResourceName();
}
this.setLocalName(this.name);
}


Expand Down Expand Up @@ -83,6 +107,22 @@ public List<Service> getProvidedServices() {
public void setProvidedServices(List<Service> providedServices) {
this.providedServices = providedServices;
}

public String getLocalName() {
return localName;
}

public void setLocalName(String localName) {
this.localName = localName.replaceAll(" ", "_");
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}


@Override
Expand All @@ -98,58 +138,75 @@ public String toString() {
* @param model Model where the resource is located.
* @return A CloudProvider object populated with its information extracted from the Semantic Model.
*/
public static CloudProvider readFromModel(Resource resource, Model model){
protected static CloudProvider readFromModel(Resource resource, Model model){

CloudProvider provider = new CloudProvider();
CloudProvider provider = null;
if(resource.getLocalName() != null && resource.getNameSpace() != null){

provider = new CloudProvider(resource.getLocalName().replaceAll("_", " "), resource.getNameSpace());


if(resource.hasProperty(FOAFEnum.NAME.getProperty(model)))
provider.setName(resource.getProperty(FOAFEnum.NAME.getProperty(model)).getString());
else{
if(resource.hasProperty(RDFSEnum.LABEL.getProperty(model)))
provider.setName(resource.getProperty(RDFSEnum.LABEL.getProperty(model)).getString());
else
{
if(resource.getLocalName() != null)
provider.setName(resource.getLocalName().replaceAll("_TIME\\d+",""));
if(resource.hasProperty(FOAFEnum.NAME.getProperty(model)))
provider.setName(resource.getProperty(FOAFEnum.NAME.getProperty(model)).getString());
else{
if(resource.hasProperty(RDFSEnum.LABEL.getProperty(model)))
provider.setName(resource.getProperty(RDFSEnum.LABEL.getProperty(model)).getString());
}

if(resource.hasProperty(RDFSEnum.COMMENT.getProperty(model)))
provider.setComment(resource.getProperty(RDFSEnum.COMMENT.getProperty(model)).getString());

//TODO: Problema a ler os links das homepages: com.hp.hpl.jena.rdf.model.LiteralRequiredException:
/*if(resource.hasProperty(FOAFEnum.HOMEPAGE.getProperty(model)))
provider.setHomepage(resource.getProperty(FOAFEnum.HOMEPAGE.getProperty(model)).getLiteral().toString());
*/
}

if(resource.hasProperty(RDFSEnum.COMMENT.getProperty(model)))
provider.setComment(resource.getProperty(RDFSEnum.COMMENT.getProperty(model)).getString());

//TODO: Problema a ler os links das homepages: com.hp.hpl.jena.rdf.model.LiteralRequiredException:
/*if(resource.hasProperty(FOAFEnum.HOMEPAGE.getProperty(model)))
provider.setHomepage(resource.getProperty(FOAFEnum.HOMEPAGE.getProperty(model)).getLiteral().toString());
*/
return provider;
}

/**
* Creates a Resource representation of the CloudProvider instance and writes it into the passed model.
* @param owner Resource that is linked to this object.
* @param model Model to where the object is to be written on.
* @throws InvalidLinkedUSDLModelException
*/
public void writeToModel(Resource owner,Model model,String baseURI)
{
protected void writeToModel(Resource owner,Model model,String baseURI) throws InvalidLinkedUSDLModelException{

Resource provider = null;

if(this.name != null)
{
provider =model.createResource(baseURI +"#" + this.name.replaceAll(" ", "_") + "_TIME" +System.nanoTime());
provider.addProperty(FOAFEnum.NAME.getProperty(model),model.createLiteral(this.name.replaceAll(" ", "_")));
}
else
{
provider =model.createResource(baseURI+ "#BusinessEntity"+ "_" +System.nanoTime());
if(this.namespace == null){ //no namespace defined for this resource, we need to define one
if(baseURI != null || !baseURI.equalsIgnoreCase("")) // the baseURI argument is valid
this.namespace = baseURI;
else //use the default baseURI
this.namespace = PricingAPIProperties.defaultBaseURI;
}

provider.addProperty(RDFEnum.RDF_TYPE.getProperty(model), model.createResource(Prefixes.GR.getPrefix() + "BusinessEntity"));//rdf type
if(this.localName != null){
LinkedUSDLValidator validator = new LinkedUSDLValidator();
validator.checkDuplicateURI(model, ResourceFactory.createResource(this.namespace + this.localName));
provider = model.createResource(this.namespace + this.localName);
if(this.name != null){
provider.addProperty(FOAFEnum.NAME.getProperty(model),model.createLiteral(this.name));
}

provider.addProperty(RDFEnum.RDF_TYPE.getProperty(model), GREnum.BUSINESS_ENTITY.getResource(model));//rdf type


owner.addProperty(USDLCoreEnum.HAS_PROVIDER.getProperty(model), provider);
}
}

protected void validate() throws InvalidLinkedUSDLModelException{

this.validateSelfData();

}

owner.addProperty(USDLCoreEnum.HAS_PROVIDER.getProperty(model), provider);
}
private void validateSelfData() throws InvalidLinkedUSDLModelException{
if(this.getName() == null || this.getName().equalsIgnoreCase("")){
throw new InvalidLinkedUSDLModelException(ErrorEnum.MISSING_RESOURCE_DATA, new String[]{this.name, "name"});
}
}


}
6 changes: 3 additions & 3 deletions SPIN_API/src/usdl/servicemodel/PriceComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void setName(String name) {
if(name != null && !name.equalsIgnoreCase("")){
this.name = name;
}else{
this.name = ResourceNameEnum.OFFERING.getResourceName();
this.name = ResourceNameEnum.PRICECOMPONENT.getResourceName();
}
this.setLocalName(this.name);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public PriceSpec calculatePrice()
* @param model Model to where the object is to be written on.
* @throws InvalidLinkedUSDLModelException
*/
public void writeToModel(Resource owner, Model model,String baseURI) throws InvalidLinkedUSDLModelException
protected void writeToModel(Resource owner, Model model,String baseURI) throws InvalidLinkedUSDLModelException
{
Resource pc = null;

Expand Down Expand Up @@ -265,7 +265,7 @@ public void writeToModel(Resource owner, Model model,String baseURI) throws Inva
* @param model Model where the resource is located.
* @return A PriceComponent object populated with its information extracted from the Semantic Model.
*/
public static PriceComponent readFromModel(Resource resource,Model model)
protected static PriceComponent readFromModel(Resource resource,Model model)
{
PriceComponent pc = null;
if(resource.getLocalName() != null && resource.getNameSpace() != null){
Expand Down
Loading

0 comments on commit d707ca9

Please sign in to comment.