Skip to content
Browse files

coding AddTRTestbed

  • Loading branch information...
1 parent 11f2f64 commit 8cdaf1375fa9567a41d180aa827ac19ff5c97d66 @whantana whantana committed Jan 20, 2012
View
6 src/main/java/eu/wisebed/wisedb/importer/TestbedImporter.java
@@ -28,7 +28,7 @@
private String urnPrefix;
/**
- * Web URL of Testbed
+ * Web URL of Testbed.
*/
private String webPageUrl;
@@ -58,7 +58,7 @@
private String sessionUrl;
/**
- * TimeZone
+ * Testbed time zone.
*/
private TimeZone timeZone;
@@ -237,7 +237,7 @@ public void convert() {
// Setting up the testbed entity
final Testbed testbed = new Testbed();
testbed.setName(getName());
- testbed.setUrnPrefix(getWebPageUrl());
+ testbed.setUrnPrefix(getUrnPrefix());
testbed.setUrl(getWebPageUrl());
testbed.setDescription(getDescription());
testbed.setFederated(isFederated());
View
14 src/test/java/eu/wisebed/wisedb/test/AddSimpleTestbed.java
@@ -9,6 +9,7 @@
import eu.wisebed.wiseml.model.setup.Node;
import eu.wisebed.wiseml.model.setup.Origin;
import eu.wisebed.wiseml.model.setup.Setup;
+import eu.wisebed.wiseml.model.setup.TimeInfo;
import org.apache.log4j.Logger;
import org.hibernate.Transaction;
@@ -26,7 +27,7 @@
/**
* a log4j logger to print messages.
*/
- private static final Logger LOGGER = Logger.getLogger(ImportTestbedEntries.class);
+ private static final Logger LOGGER = Logger.getLogger(AddSimpleTestbed.class);
public static void main(final String[] args) throws IOException {
@@ -52,6 +53,7 @@ public static void main(final String[] args) throws IOException {
final String testbedWebPageUrl = br.readLine();
tImp.setWebPageUrl(testbedWebPageUrl);
+ LOGGER.info("Using your default TimeZone : " + TimeZone.getDefault().getDisplayName());
tImp.setTimeZone(TimeZone.getDefault());
// Initialize hibernate and begin transaction
@@ -65,6 +67,7 @@ public static void main(final String[] args) throws IOException {
tx.commit();
// begin transaction
+ LOGGER.info("For testbed : " + testbedName + " the default setup will be added");
tx = HibernateUtil.getInstance().getSession().beginTransaction();
Testbed testbed = TestbedController.getInstance().getByName(testbedName);
@@ -75,11 +78,12 @@ public static void main(final String[] args) throws IOException {
Origin origin = new Origin();
origin.setPhi(0);
origin.setTheta(0);
- origin.setX((float) 1.0);
- origin.setY((float) 2.0);
- origin.setZ((float)3.0);
+ origin.setX((float) 0.0);
+ origin.setY((float) 0.0);
+ origin.setZ((float) 0.0);
setup.setOrigin(origin);
- setup.setTimeinfo(null);
+ setup.setTimeinfo(new TimeInfo());
+ setup.setCoordinateType("Absolute");
// import by the convert method
sImp.setTestbed(testbed);
View
97 src/test/java/eu/wisebed/wisedb/test/AddTRTestbed.java
@@ -1,7 +1,102 @@
package eu.wisebed.wisedb.test;
+import eu.wisebed.wisedb.HibernateUtil;
+import eu.wisebed.wisedb.controller.TestbedController;
+import eu.wisebed.wisedb.importer.SetupImporter;
+import eu.wisebed.wisedb.importer.TestbedImporter;
+import eu.wisebed.wisedb.model.Testbed;
+import org.apache.log4j.Logger;
+import org.hibernate.Transaction;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.TimeZone;
+
/**
* Add TR Testbed.
*/
public class AddTRTestbed {
-}
+
+ /**
+ * a log4j logger to print messages.
+ */
+ private static final Logger LOGGER = Logger.getLogger(AddTRTestbed.class);
+
+
+ public static void main(String args[]) throws IOException {
+
+ // Construct a TestbedImporter and a Setup Importer
+ final TestbedImporter tImp = new TestbedImporter();
+ final SetupImporter sImp = new SetupImporter();
+
+ // read from keyboard.
+ BufferedReader br;
+ br = new BufferedReader(new InputStreamReader(System.in));
+
+ try {
+ LOGGER.info("Provide Testbed Name");
+ final String testbedName = br.readLine();
+ tImp.setName(testbedName);
+
+ LOGGER.info("Provide Testbed Description");
+ final String testbedDescription = br.readLine();
+ tImp.setDescription(testbedDescription);
+
+ LOGGER.info("Provide Testbed's web page URL");
+ final String testbedWebPageUrl = br.readLine();
+ tImp.setWebPageUrl(testbedWebPageUrl);
+
+ LOGGER.info("Provide Testbed's SNAA URL");
+ final String testbedSNAAUrl = br.readLine();
+ tImp.setSnaaUrl(testbedSNAAUrl);
+
+ LOGGER.info("Provide Testbed's RS URL");
+ final String testbedRSUrl = br.readLine();
+ tImp.setSnaaUrl(testbedRSUrl);
+
+ LOGGER.info("Provide Testbed's Session Management URL");
+ final String testbedSMUrl = br.readLine();
+ tImp.setSessionUrl(testbedSMUrl);
+
+ String yesOrNo;
+ do{
+ LOGGER.info("Provide \"Yes\" if testbed is federated , otherwise provvide \"No\".");
+ yesOrNo = br.readLine();
+ }while(!(yesOrNo.equals("Yes") || yesOrNo.equals("No")));
+ tImp.setFederated(yesOrNo.equals("Yes"));
+
+
+ LOGGER.info("Using your default TimeZone : " + TimeZone.getDefault().getDisplayName());
+ tImp.setTimeZone(TimeZone.getDefault());
+
+ // Initialize hibernate and begin transaction
+ HibernateUtil.connectEntityManagers();
+ Transaction tx = HibernateUtil.getInstance().getSession().beginTransaction();
+
+ // import to db
+ tImp.convert();
+
+ // commmit transaction
+ tx.commit();
+
+ // begin transaction
+ LOGGER.info("For testbed : " + testbedName + " we retrieve it's setup through the SessionManagment webservice.");
+ tx = HibernateUtil.getInstance().getSession().beginTransaction();
+ Testbed testbed = TestbedController.getInstance().getByName(testbedName);
+
+ // import by the convert method
+ sImp.setTestbed(testbed);
+ sImp.connect();
+ sImp.convert();
+
+ tx.commit();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ // always close session
+ HibernateUtil.getInstance().closeSession();
+ }
+ }
+}

0 comments on commit 8cdaf13

Please sign in to comment.
Something went wrong with that request. Please try again.