public static void main(String[] args) throws IOException, InvalidLinkedUSDLModelException { LinkedUSDLModel jmodel; jmodel = LinkedUSDLModelFactory.createEmptyModel(); CloudSigmaRecurrentSubsOffering(jmodel); jmodel.setBaseURI("http://PricingAPICloudSigma6MRecurrentSubscription.com"); Model instance = jmodel.WriteToModel(); // transform the java models to a semantic representation File outputFile = new File("./DebuggingFiles/CloudsigmaRS.ttl"); if (!outputFile.exists()) { outputFile.createNewFile(); } FileOutputStream out = new FileOutputStream(outputFile); instance.write(out, "Turtle"); out.close(); }
@SuppressWarnings("resource") public static void main(String[] args) { LinkedUSDLModel jmodel; try { jmodel = LinkedUSDLModelFactory.createFromModel( "./DebuggingFiles/MAzureSmallPrePaid6m.ttl"); // read a generic model // System.out.println(jmodel.toString()); // set variables values List<Offering> myOfferings = jmodel.getOfferings(); HashMap<String, Usage> definedVariables = new HashMap<String, Usage>(); for (Offering off : myOfferings) // for each offering { if (off.getPricePlan() != null) // if it has a price plan { PricePlan pp = off.getPricePlan(); for (PriceComponent pc : pp.getPriceComponents()) // for every component of the priceplan { if (pc.getPriceFunction() != null) // if it has a price function { PriceFunction pf = pc.getPriceFunction(); // System.out.println("Off: "+off.getName()); // System.out.println(pf.getSPARQLFunction()); List<Usage> usageVars = pf.getUsageVariables(); // fetch its usage variables Collections.sort( usageVars, new Comparator< Usage>() { // sort them alphabetically, this can be included in the API public int compare(Usage s1, Usage s2) { return s1.getName().compareTo(s2.getName()); } }); for (Usage var : usageVars) // for each usage var, set a value. { if (!definedVariables.containsKey(var.getName().replaceAll("TIME\\d+.*", ""))) { QuantitativeValue val = new QuantitativeValue(); Scanner scan = new Scanner(System.in); System.out.println( "Insert the value for the " + var.getName().replaceAll("TIME\\d+.*", "") + " variable.\nDetails: \n" + var.getComment()); double num = Double.parseDouble(scan.nextLine()); val.setValue(num); // 1month var.setValue(val); // add the new value to the usage variable definedVariables.put(var.getName().replaceAll("TIME\\d+.*", ""), var); } else { var.setValue( new QuantitativeValue( (QuantitativeValue) definedVariables .get(var.getName().replaceAll("TIME\\d+.*", "")) .getValue())); } } } } } else System.out.println("Offering with a null price plan"); } jmodel.setBaseURI("http://PricingAPIMAzureInstance.com"); Model instance = jmodel .WriteToModel(); // after we've done our changes in the jmodels, we transform them // into a new Semantic model /*//write model to file File outputFile = new File("./ma.ttl"); if (!outputFile.exists()) { outputFile.createNewFile(); } FileOutputStream out = new FileOutputStream(outputFile); instance.write(out, "Turtle"); out.close();*/ // after applying the changes to the jmodels and transforming them to a semantic web // representation, we can calculate the prices of every offerings. for (Offering off : myOfferings) System.out.println( "" + off.getName() + ", Price:" + off.getPricePlan().calculatePrice(instance)); // jmodel.writeModelToFile("./serviceExamples/test.ttl", "baseURI/de_teste", "TTL"); } catch (InvalidLinkedUSDLModelException | IOException | ReadModelException e) { e.printStackTrace(); } }