aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Eck II2012-07-17 13:59:03 (EDT)
committerTim Eck II2012-07-17 13:59:03 (EDT)
commitb64700d53758b2152f91a005ce4cdb637894fe36 (patch)
tree97628312ecc0307a5b0328804ade81eeccc211ae
parent0c02220f9cbfc5c48000d44e217be06171088d4f (diff)
downloadorg.eclipse.lyo.testsuite-b64700d53758b2152f91a005ce4cdb637894fe36.zip
org.eclipse.lyo.testsuite-b64700d53758b2152f91a005ce4cdb637894fe36.tar.gz
org.eclipse.lyo.testsuite-b64700d53758b2152f91a005ce4cdb637894fe36.tar.bz2
Created a tool to allow someone to generate the configuration files thatrefs/changes/25/6825/1
will allow Lyo to run against RAM Bug 385335 https://bugs.eclipse.org/bugs/show_bug.cgi?id=385335
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/HowTo.txt18
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/exampleProperty.properties49
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/create.json19
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createArtifact.json16
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createCategory.json22
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createRelationship.json26
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/update.json19
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/setup.properties51
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/testArtifact.txt1
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/create.xml7
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createArtifact.xml13
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createCategory.xml17
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createRelationship.xml19
-rw-r--r--org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/update.xml1
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/tools/RAMConfigTool.java310
15 files changed, 588 insertions, 0 deletions
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/HowTo.txt b/org.eclipse.lyo.testsuite.server/RamConfigTool/HowTo.txt
new file mode 100644
index 0000000..89b23bc
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/HowTo.txt
@@ -0,0 +1,18 @@
+Instructions about how to use this application.
+
+The application accepts two arguments:
+1) The location of the properties files
+2) -z flag
+
+The first argument must be passed everything and must be the first argument passed. This tells
+the application where the properties file is that contains the settings used to generate the
+configuration file for the lyo tests. To learn more about the various settings please read the
+exampleProperty.properties file.
+
+The second argument tells the application to create a zip file instead of a folders and files.
+
+Note that this application creates configurations for Lyo tests to run against RAM APIs.
+You can modify the generated files to run against other APIs that implement the asset management
+specification but this application will not do that for you.
+
+Also the templates folder must be in the root directory in order for the tool to find it \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/exampleProperty.properties b/org.eclipse.lyo.testsuite.server/RamConfigTool/exampleProperty.properties
new file mode 100644
index 0000000..bd13672
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/exampleProperty.properties
@@ -0,0 +1,49 @@
+####################
+#General Properties#
+####################
+
+#Location to save the config folder or zip too. Default is in the directory config/
+outputLocation=config/test/
+
+#This is only used if the -z flag is passed. Default is config.zip
+#outputFileName=test.zip
+
+#The url to ram. Do not add .ws or /. These will be added where necessary.
+ramUrl=http://localhost:8080/ram
+
+#######################
+#Setup Properties File#
+#######################
+
+# Required to set the authentication settings
+# Supported values BASIC, FORM, OAUTH. If this is not found the value is assumed to be basic
+authMethod=BASIC
+
+# This is only required if the authMethod is FORM
+#formUri=http://localhost:8080/ram.ws/j_security_check
+
+# The authentication credentials
+userId=admin
+pw=admin
+
+# This should be the name of an asset that is already created. The tests will query for the asset
+# by this name.
+queryAssetName=Customer Care Web Application
+
+# This date will be used is a query to compare assets by when they where modified.
+queryAssetModificationDate=2010-08-16T20:16:03.578Z
+
+###########################
+#Asset Template Properties#
+###########################
+
+assetType=documentation
+assetCommunity=1001
+assetCategory=software_development.xmi#open_source
+assetRelationship=documentation
+
+################################################################################################
+#Final Note #
+#If you are not sure what each setting does then just run the tool with this file and then read#
+#what is generated. Hopefully that will give you a better understanding each setting does. #
+################################################################################################ \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/create.json b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/create.json
new file mode 100644
index 0000000..93d49e7
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/create.json
@@ -0,0 +1,19 @@
+{
+ "prefixes" : {
+ "oslc": "http://open-services.net/ns/core#",
+ "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "dcterms" : "http://purl.org/dc/terms/",
+ "oslc_asset" : "http://open-services.net/ns/asset#",
+ "ram_asset" : "http://jazz.net/xmlns/prod/ram/2.0/"
+ },
+ "oslc_asset:version" : "1.0",
+ "rdf:type": {
+ "rdf:resource" : "*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"
+ },
+ "community":
+ {
+ "resource":"*ramUrl*.ws/internal/communities/*assetCommunity*"
+ },
+ "dcterms:abstract" : "OSLCv2 Creation test case",
+ "dcterms:title" : "Created Asset"
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createArtifact.json b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createArtifact.json
new file mode 100644
index 0000000..c09dac3
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createArtifact.json
@@ -0,0 +1,16 @@
+{
+ "prefixes" : {
+ "oslc": "http://open-services.net/ns/core#",
+ "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "dcterms" : "http://purl.org/dc/terms/"
+ },
+ "dcterms:title" : "Build help documentation",
+ "oslc:label" : "documentation",
+ "oslc_asset:content" : {
+ "rdf:resource" : "http://help.example.com"
+ },
+ "dcterms:format" : "text/html",
+ "rdf:type" : {
+ "rdf:resource" : "http://open-services.net/ns/asset#Artifact"
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createCategory.json b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createCategory.json
new file mode 100644
index 0000000..332078e
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createCategory.json
@@ -0,0 +1,22 @@
+{
+ "prefixes" : {
+ "oslc": "http://open-services.net/ns/core#",
+ "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "dcterms" : "http://purl.org/dc/terms/",
+ "oslc_asset" : "http://open-services.net/ns/asset#",
+ "ram_asset" : "http://jazz.net/xmlns/prod/ram/2.0/"
+ },
+ "oslc_asset:version" : "1.0",
+ "rdf:type": {
+ "rdf:resource" : "*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"
+ },
+ "oslc_asset:categorization" : {
+ "rdf:resource" : "*ramUrl*.ws/internal/communities/*assetCommunity*"
+ },
+ "community":
+ {
+ "resource":"*ramUrl*.ws/internal/communities/*assetCommunity*"
+ },
+ "dcterms:abstract" : "OSLCv2 Creation test case",
+ "dcterms:title" : "OSLCv2 asset testing"
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createRelationship.json b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createRelationship.json
new file mode 100644
index 0000000..3be9caf
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/createRelationship.json
@@ -0,0 +1,26 @@
+{
+ "prefixes" : {
+ "oslc": "http://open-services.net/ns/core#",
+ "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "dcterms" : "http://purl.org/dc/terms/",
+ "oslc_asset" : "http://open-services.net/ns/asset#",
+ "ram_asset" : "http://jazz.net/xmlns/prod/ram/2.0/"
+ },
+ "oslc_asset:version" : "1.0",
+ "rdf:type": {
+ "rdf:resource" : "*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"
+ },
+ "dcterms:relation" : {
+ "rdf:ID" : "relationship1",
+ "rdf:resource" : "%s",
+ "oslc_asset:relationshipType" : {
+ "rdf:resource" : "*ramUrl*.ws/internal/relationshipTypes/*assetRelationship*"
+ }
+ },
+ "community":
+ {
+ "resource":"*ramUrl*.ws/internal/communities/*assetCommunity*"
+ },
+ "dcterms:abstract" : "OSLCv2 Creation test case",
+ "dcterms:title" : "OSLCv2 asset testing"
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/update.json b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/update.json
new file mode 100644
index 0000000..ec91b25
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/json/update.json
@@ -0,0 +1,19 @@
+{
+ "prefixes" : {
+ "oslc": "http://open-services.net/ns/core#",
+ "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "dcterms" : "http://purl.org/dc/terms/",
+ "oslc_asset" : "http://open-services.net/ns/asset#",
+ "ram_asset" : "http://jazz.net/xmlns/prod/ram/2.0/"
+ },
+ "oslc_asset:version" : "1.0",
+ "rdf:type": {
+ "rdf:resource" : "*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"
+ },
+ "community":
+ {
+ "resource":"*ramUrl*.ws/internal/communities/*assetCommunity*"
+ },
+ "dcterms:abstract" : "OSLCv2 Creation test case",
+ "dcterms:title" : "Updated Asset"
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/setup.properties b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/setup.properties
new file mode 100644
index 0000000..62bf2a7
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/setup.properties
@@ -0,0 +1,51 @@
+##GENERAL PROPERTIES##
+#The location of the top level ServiceProviderCatalog or Service Description Document
+baseUri=*ramUrl*.ws/oslc/servicesCatalog
+#Implementation name (for identification purposes)
+implName=rio-asset Dev
+#The authentication style (currently supports only BASIC, FORM and OAUTH)
+authMethod=*authMethod*
+*formUri*
+#The authentication credentials
+userId=*userId*
+pw=*pw*
+
+testVersions=http://open-services.net/ns/asset#
+
+##QUERY PROPERTIES##
+#The query parameter that should be used to test equality
+queryEqualityProperty=dcterms:title
+#The parameter value used with the parameter to test equality (record with this value should exist in the system)
+queryEqualityValue=*queryAssetName*
+#The query parameter that should be used to test equality
+queryComparisonProperty=dcterms:modified
+#The parameter value used with the parameter to test comparisons (should split the results into two non-empty sets)
+queryComparisonValue=*queryAssetModificationDate*
+#Additional non-OSLC parameters that need to be included to run queries
+queryAdditionalParameters=
+#A value to test full text search against (should return a non-empty record list)
+fullTextSearchTerm=This asset was created
+
+##CREATION AND UPDATION PROPERTIES##
+#Location of properly formatted xml/rdf which will be used to create an asset
+createTemplateArtifactXmlFile=*location*xml/createArtifact.xml
+createTemplateArtifactJsonFile=*location*json/createArtifact.json
+
+#Location of properly formatted xml which will be used to update a record.
+createTemplateXmlFile=*location*xml/create.xml
+updateTemplateXmlFile=*location*xml/update.xml
+
+createTemplateJsonFile=*location*json/create.json
+updateTemplateJsonFile=*location*json/create.json
+
+createWithCategoryTemplateXmlFile=*location*xml/createCategory.xml
+createWithCategoryTemplateJsonFile=*location*json/createCategory.json
+
+createWithRelationshipTemplateXmlFile=*location*xml/createRelationship.xml
+createWithRelationshipTemplateJsonFile=*location*json/createRelationship.json
+
+artifactFile=*location*testArtifact.txt
+artifactContentType=text/plain
+#This is the base service url used by jena to read/write models
+baseUrl=*ramUrl*
+useThisServiceProvider=*ramUrl*.ws/oslc/assetServices \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/testArtifact.txt b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/testArtifact.txt
new file mode 100644
index 0000000..e374983
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/testArtifact.txt
@@ -0,0 +1 @@
+This is to be used as a test artifact. The text here really doesn't matter so you can replace this text with whatever you want. \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/create.xml b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/create.xml
new file mode 100644
index 0000000..6d31f74
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/create.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#" xmlns:oslc_asset="http://open-services.net/ns/asset#" xmlns:ram_asset="http://jazz.net/xmlns/prod/ram/2.0/"> <oslc_asset:Asset> <rdf:type rdf:resource="http://open-services.net/ns/asset#Asset"/>
+ <dcterms:type rdf:resource="*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"/>
+ <dcterms:title>Create asset</dcterms:title>
+ <oslc_asset:version>1.0</oslc_asset:version>
+ <dcterms:abstract>This asset was created</dcterms:abstract>
+ <ram_asset:community rdf:resource="*ramUrl*.ws/internal/communities/*assetCommunity*"/> </oslc_asset:Asset> </rdf:RDF> \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createArtifact.xml b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createArtifact.xml
new file mode 100644
index 0000000..d5b8618
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createArtifact.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:oslc="http://open-services.net/ns/core#"
+ xmlns:oslc_asset="http://open-services.net/ns/artifact#">
+ <oslc_asset:Artifact>
+ <rdf:type rdf:resource="http://open-services.net/ns/asset#Artifact"/>
+ <dcterms:title>Build help documentation</oslc:label>
+ <oslc:label>documentation</dcterms:label>
+ <oslc_asset:content rdf:resource="http://help.example.com"/>
+ <dcterms:format>text/html</dcterms:format>
+ </oslc_asset:Artifact>
+</rdf:RDF> \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createCategory.xml b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createCategory.xml
new file mode 100644
index 0000000..a22b396
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createCategory.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:oslc="http://open-services.net/ns/core#"
+ xmlns:oslc_asset="http://open-services.net/ns/asset#"
+ xmlns:ram_asset="http://jazz.net/xmlns/prod/ram/2.0/">
+ <oslc_asset:Asset>
+ <rdf:type rdf:resource="http://open-services.net/ns/asset#Asset"/>
+ <dcterms:type rdf:resource="*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"/>
+ <dcterms:title>asset with category</dcterms:title>
+ <oslc_asset:version>1.0</oslc_asset:version>
+ <dcterms:abstract>OSLCv2 Creation test case</dcterms:abstract>
+ <ram_asset:community rdf:resource="*ramUrl*.ws/internal/communities/*assetCommunity*"/>
+ <oslc_asset:categorization rdf:resource="*ramUrl*.ws/internal/categories/classif/*assetCategory*"/>
+ </oslc_asset:Asset>
+
+</rdf:RDF> \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createRelationship.xml b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createRelationship.xml
new file mode 100644
index 0000000..8b7f429
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/createRelationship.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:oslc="http://open-services.net/ns/core#"
+ xmlns:oslc_asset="http://open-services.net/ns/asset#"
+ xmlns:ram_asset="http://jazz.net/xmlns/prod/ram/2.0/">
+ <oslc_asset:Asset>
+ <rdf:type rdf:resource="http://open-services.net/ns/asset#Asset"/>
+ <dcterms:type rdf:resource="*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"/>
+ <dcterms:title>Asset with relation</dcterms:title>
+ <oslc_asset:version>1.0</oslc_asset:version>
+ <dcterms:abstract>Related asset test</dcterms:abstract>
+ <dcterms:relation rdf:ID="relationship1" rdf:resource="%s"/>
+ <ram_asset:community rdf:resource="*ramUrl*.ws/internal/communities/*assetCommunity*"/>
+ </oslc_asset:Asset>
+ <rdf:Description rdf:about="#relationship1">
+ <oslc_asset:relationshipType rdf:resource="*ramUrl*.ws/internal/relationshipTypes/*assetRelationship*"/>
+ </rdf:Description>
+</rdf:RDF> \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/update.xml b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/update.xml
new file mode 100644
index 0000000..c0ac564
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/RamConfigTool/templates/xml/update.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#" xmlns:oslc_asset="http://open-services.net/ns/asset#" xmlns:ram_asset="http://jazz.net/xmlns/prod/ram/2.0/"> <oslc_asset:Asset> <rdf:type rdf:resource="http://open-services.net/ns/asset#Asset"/> <dcterms:type rdf:resource="*ramUrl*.ws/internal/types/classif/assetTypesSchema.xmi#*assetType*"/> <dcterms:title>Updated asset</dcterms:title> <oslc_asset:version>1.0</oslc_asset:version> <dcterms:abstract>This asset was created</dcterms:abstract> <ram_asset:revisionCount>1</ram_asset:revisionCount> <ram_asset:community rdf:resource="*ramUrl*.ws/internal/communities/*assetCommunity*"/> </oslc_asset:Asset> </rdf:RDF> \ No newline at end of file
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/tools/RAMConfigTool.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/tools/RAMConfigTool.java
new file mode 100644
index 0000000..dd69168
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/tools/RAMConfigTool.java
@@ -0,0 +1,310 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Tim Eck II - asset management test cases and RAMConfigTool
+ *******************************************************************************/
+package org.eclipse.lyo.testsuite.tools;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * This tool generates configurations to be used to run the lyo test suite against Rational Asset Manager.
+ */
+public class RAMConfigTool {
+ private static Properties properties;
+
+ private static String TEMPLATE_DIR = "templates/";
+ private static String XML_DIR = TEMPLATE_DIR + "xml/";
+ private static String JSON_DIR = TEMPLATE_DIR + "json/";
+
+ private static String xmlCreateTemplate;
+ private static String xmlArtifactTemplate;
+ private static String xmlCategoryTemplate;
+ private static String xmlRelationshipTemplate;
+ private static String xmlUpdateTemplate;
+
+ private static String jsonCreateTemplate;
+ private static String jsonArtifactTemplate;
+ private static String jsonCategoryTemplate;
+ private static String jsonRelationshipTemplate;
+ private static String jsonUpdateTemplate;
+
+ private static String testArtifactTemplate;
+ private static String setupPropertyTemplate;
+
+
+ /**
+ * first arg is file name, if second is -z then a zip file is created
+ * @param args
+ */
+ public static void main(String[] args){
+ // Verify the file arg might exist
+ if(args.length < 1) {
+ System.out.println("No file name was specified. The first argument needs to the file path to the properties file.");
+ return;
+ }
+
+ // Attempt to read the properties
+ try {
+ setupProperties(args[0]);
+ } catch (IOException e) {
+ System.out.println("The specified file passed could no be read. Please verify that the file exists and is properly formatted");
+ return;
+ }
+
+ // Reads all the template files
+ try {
+ xmlCreateTemplate = readFile(XML_DIR + "create.xml");
+ xmlArtifactTemplate = readFile(XML_DIR + "createArtifact.xml");
+ xmlCategoryTemplate = readFile(XML_DIR + "createCategory.xml");
+ xmlRelationshipTemplate = readFile(XML_DIR + "createRelationship.xml");
+ xmlUpdateTemplate = readFile(XML_DIR + "update.xml");
+
+ jsonCreateTemplate = readFile(JSON_DIR + "create.json");
+ jsonArtifactTemplate = readFile(JSON_DIR + "createArtifact.json");
+ jsonCategoryTemplate = readFile(JSON_DIR + "createCategory.json");
+ jsonRelationshipTemplate = readFile(JSON_DIR + "createRelationship.json");
+ jsonUpdateTemplate = readFile(JSON_DIR + "update.json");
+
+ testArtifactTemplate = readFile(TEMPLATE_DIR + "testArtifact.txt");
+ setupPropertyTemplate = readFile(TEMPLATE_DIR + "setup.properties");
+ } catch (IOException e) {
+ System.out.println("Could not read the template files. Please verify that they are where they should be and can be read");
+ return;
+ }
+
+ // Fill in templates
+ try {
+ fillInTemplates();
+ } catch (NullPointerException e) {
+ System.out.println("There where properties settings not found in the the properties file. Could not generate configuration.");
+ return;
+ }
+
+ // Sets up the output location
+ String outputLocation = properties.getProperty("outputLocation");
+ if(outputLocation == null)
+ outputLocation = "config/";
+
+ boolean zip = false;
+ if(args.length > 1)
+ zip = args[1].toLowerCase().equals("-z");
+
+ // Writes the configs to disk
+ try {
+ writeConfig(outputLocation, zip);
+ } catch (IOException e) {
+ System.out.println("Could not write the config files to disk");
+ return;
+ }
+ System.out.println("The configuration have been created successfully");
+ }
+
+ private static void setupProperties(String propertyFile) throws IOException {
+ InputStream is = new FileInputStream(propertyFile);
+ properties = new Properties();
+ properties.load(is);
+ }
+
+ private static String readFile(String fileName) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(fileName));
+ StringBuilder stringBuilder = new StringBuilder();
+ String ls = System.getProperty("line.separator");
+
+ String line = reader.readLine();
+ while(line != null) {
+ stringBuilder.append( line );
+ stringBuilder.append( ls );
+ line = reader.readLine();
+ }
+
+ String contents = stringBuilder.toString();
+ reader.close();
+ return contents;
+ }
+
+ private static void fillInTemplates() throws NullPointerException {
+ String ramUrl = properties.getProperty("ramUrl");
+ if(ramUrl == null)
+ throw new NullPointerException();
+
+ // Update the setup.properties template
+ setupPropertyTemplate = setupPropertyTemplate.replace("*ramUrl*", ramUrl);
+ String authMethod = properties.getProperty("authMethod");
+ if(authMethod == null)
+ authMethod = "BASIC";
+ authMethod = authMethod.toUpperCase();
+ setupPropertyTemplate = setupPropertyTemplate.replace("*authMethod*", authMethod);
+
+ String formUri = properties.getProperty("formUri");
+ if(authMethod.equals("FORM") && formUri == null)
+ throw new NullPointerException();
+ else
+ formUri = "";
+ setupPropertyTemplate = setupPropertyTemplate.replace("*formUri*", formUri);
+
+ String userId = properties.getProperty("userId");
+ String pw = properties.getProperty("pw");
+ if(userId == null || pw == null)
+ throw new NullPointerException();
+ setupPropertyTemplate = setupPropertyTemplate.replace("*userId*", userId);
+ setupPropertyTemplate = setupPropertyTemplate.replace("*pw*", pw);
+
+ String outputLocation = properties.getProperty("outputLocation");
+ if(outputLocation == null)
+ outputLocation = "config/";
+ setupPropertyTemplate = setupPropertyTemplate.replace("*location*", outputLocation);
+
+ String queryAssetName = properties.getProperty("queryAssetName");
+ String queryAssetModificationDate = properties.getProperty("queryAssetModificationDate");
+ if(queryAssetName == null || queryAssetModificationDate == null)
+ throw new NullPointerException();
+ setupPropertyTemplate = setupPropertyTemplate.replace("*queryAssetName*", queryAssetName);
+ setupPropertyTemplate = setupPropertyTemplate.replace("*queryAssetModificationDate*", queryAssetModificationDate);
+
+
+ // Set up the property values for the xml/json file templates
+ String assetType = properties.getProperty("assetType");
+ String assetCommunity = properties.getProperty("assetCommunity");
+ String assetCategory = properties.getProperty("assetCategory");
+ String assetRelationship = properties.getProperty("assetRelationship");
+ if(assetType == null || assetCommunity == null ||
+ assetCategory == null || assetRelationship == null)
+ throw new NullPointerException();
+
+ // Update the xml file templates
+ xmlCreateTemplate = xmlCreateTemplate.replace("*ramUrl*", ramUrl);
+ xmlCreateTemplate = xmlCreateTemplate.replace("*assetType*", assetType);
+ xmlCreateTemplate = xmlCreateTemplate.replace("*assetCommunity*", assetCommunity);
+
+ xmlCategoryTemplate = xmlCategoryTemplate.replace("*ramUrl*", ramUrl);
+ xmlCategoryTemplate = xmlCategoryTemplate.replace("*assetType*", assetType);
+ xmlCategoryTemplate = xmlCategoryTemplate.replace("*assetCommunity*", assetCommunity);
+ xmlCategoryTemplate = xmlCategoryTemplate.replace("*assetCategory*", assetCategory);
+
+ xmlRelationshipTemplate = xmlRelationshipTemplate.replace("*ramUrl*", ramUrl);
+ xmlRelationshipTemplate = xmlRelationshipTemplate.replace("*assetType*", assetType);
+ xmlRelationshipTemplate = xmlRelationshipTemplate.replace("*assetCommunity*", assetCommunity);
+ xmlRelationshipTemplate = xmlRelationshipTemplate.replace("*assetRelationship*", assetRelationship);
+
+ xmlUpdateTemplate = xmlUpdateTemplate.replace("*ramUrl*", ramUrl);
+ xmlUpdateTemplate = xmlUpdateTemplate.replace("*assetType*", assetType);
+ xmlUpdateTemplate = xmlUpdateTemplate.replace("*assetCommunity*", assetCommunity);
+
+ // Update the json file templates
+ jsonCreateTemplate = jsonCreateTemplate.replace("*ramUrl*", ramUrl);
+ jsonCreateTemplate = jsonCreateTemplate.replace("*assetType*", assetType);
+ jsonCreateTemplate = jsonCreateTemplate.replace("*assetCommunity*", assetCommunity);
+
+ jsonCategoryTemplate = jsonCategoryTemplate.replace("*ramUrl*", ramUrl);
+ jsonCategoryTemplate = jsonCategoryTemplate.replace("*assetType*", assetType);
+ jsonCategoryTemplate = jsonCategoryTemplate.replace("*assetCommunity*", assetCommunity);
+ jsonCategoryTemplate = jsonCategoryTemplate.replace("*assetCategory*", assetCategory);
+
+ jsonRelationshipTemplate = jsonRelationshipTemplate.replace("*ramUrl*", ramUrl);
+ jsonRelationshipTemplate = jsonRelationshipTemplate.replace("*assetType*", assetType);
+ jsonRelationshipTemplate = jsonRelationshipTemplate.replace("*assetCommunity*", assetCommunity);
+ jsonRelationshipTemplate = jsonRelationshipTemplate.replace("*assetRelationship", assetRelationship);
+
+ jsonUpdateTemplate = jsonUpdateTemplate.replace("*ramUrl*", ramUrl);
+ jsonUpdateTemplate = jsonUpdateTemplate.replace("*assetType*", assetType);
+ jsonUpdateTemplate = jsonUpdateTemplate.replace("*assetCommunity*", assetCommunity);
+ }
+
+ private static void writeConfig(String location, boolean createZip) throws IOException {
+ File directory = new File(location);
+ if(!directory.exists())
+ directory.mkdirs();
+
+ if(createZip) {
+ String zipFileName = properties.getProperty("outputFileName");
+ if(zipFileName == null)
+ zipFileName = "config.zip";
+
+ ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(location + zipFileName));
+
+ addToZip(zip, "xml/", "create", "xml", xmlCreateTemplate);
+ addToZip(zip, "xml/", "createArtifact", "xml", xmlArtifactTemplate);
+ addToZip(zip, "xml/", "createCategory", "xml", xmlCategoryTemplate);
+ addToZip(zip, "xml/", "createRelationship", "xml", xmlRelationshipTemplate);
+ addToZip(zip, "xml/", "update", "xml", xmlUpdateTemplate);
+
+ addToZip(zip, "json/", "create", "json", jsonCreateTemplate);
+ addToZip(zip, "json/", "createArtifact", "json", jsonArtifactTemplate);
+ addToZip(zip, "json/", "createCategory", "json", jsonCategoryTemplate);
+ addToZip(zip, "json/", "createRelationship", "json", jsonRelationshipTemplate);
+ addToZip(zip, "json/", "update", "json", jsonUpdateTemplate);
+
+ addToZip(zip, "", "setup", "properties", setupPropertyTemplate);
+ addToZip(zip, "", "testArtifact", "properties", testArtifactTemplate);
+ zip.close();
+
+ } else {
+ directory = new File(location + "xml/");
+ if(!directory.exists())
+ directory.mkdirs();
+
+ directory = new File(location + "json/");
+ if(!directory.exists())
+ directory.mkdirs();
+
+
+ writeFile(location + "xml/create.xml", xmlCreateTemplate);
+ writeFile(location + "xml/createArtifact.xml", xmlArtifactTemplate);
+ writeFile(location + "xml/createCategory.xml", xmlCategoryTemplate);
+ writeFile(location + "xml/createRelationship.xml", xmlRelationshipTemplate);
+ writeFile(location + "xml/update.xml", xmlUpdateTemplate);
+
+ writeFile(location + "json/create.json", jsonCreateTemplate);
+ writeFile(location + "json/createArtifact.json", jsonArtifactTemplate);
+ writeFile(location + "json/createCategory.json", jsonCategoryTemplate);
+ writeFile(location + "json/createRelationship.json", jsonRelationshipTemplate);
+ writeFile(location + "json/update.json", jsonUpdateTemplate);
+
+ writeFile(location + "setup.properties", setupPropertyTemplate);
+ writeFile(location + "testArtifact.txt", testArtifactTemplate);
+ }
+ }
+
+ private static void writeFile(String location, String content) throws IOException {
+ FileWriter writer = new FileWriter(location);
+ writer.append(content);
+ writer.close();
+ }
+
+ private static void addToZip(ZipOutputStream zip, String directory, String fileName,
+ String extention, String content) throws IOException {
+ zip.putNextEntry(new ZipEntry(directory+ fileName + "." + extention));
+ File temp = File.createTempFile(fileName, extention);
+
+ FileWriter tempWriter = new FileWriter(temp);
+ tempWriter.append(content);
+ tempWriter.close();
+
+ InputStream in = new FileInputStream(temp);
+ byte[] b = new byte[1024];
+ int count;
+ while ((count = in.read(b)) > 0) {
+ zip.write(b, 0, count);
+ }
+ }
+} \ No newline at end of file