|
From: <ian...@us...> - 2007-09-05 23:18:47
|
Revision: 371
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=371&view=rev
Author: iansmith
Date: 2007-09-05 16:18:49 -0700 (Wed, 05 Sep 2007)
Log Message:
-----------
New Mojos for populate and reverse populate.
Modified Paths:
--------------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
maven/trunk/ogoglio-server/pom.xml
maven/trunk/ogoglio-server/src/main/resources/populate/space-1
Added Paths:
-----------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java
Added: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java (rev 0)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java 2007-09-05 23:18:49 UTC (rev 371)
@@ -0,0 +1,98 @@
+package com.ogoglio.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.xml.TemplateDocument;
+
+public abstract class OgServiceMojoBase extends AbstractMojo {
+
+ protected static final String SPACE_PREFIX = "space-";
+ protected static final String TEMPLATE_PREFIX = "template-";
+ /**
+ * @parameter
+ */
+ protected File populateDir;
+ /**
+ * @parameter
+ */
+ protected String serviceURI;
+ /**
+ * @parameter
+ */
+ protected String username;
+ /**
+ * @parameter
+ */
+ private String password;
+
+ protected WebAPIClient validateArgsAndConnect() {
+ if (populateDir == null) {
+ getLog().info("No populate baseDir given. Mojo ignored.");
+ return null;
+ }
+
+ if ((!populateDir.exists()) || (!populateDir.isDirectory())
+ || (!populateDir.canRead())) {
+ getLog().error(
+ "Unable to access base dir:" + populateDir.getAbsolutePath());
+ return null;
+ }
+
+ if (serviceURI == null) {
+ getLog().info("No populate serviceURI given. Mojo ignored.");
+ return null;
+ }
+ try {
+ WebAPIClientWire wire = new WebAPIClientWire();
+ WebAPIDescriptor descriptor = new WebAPIDescriptor(new URI(
+ serviceURI));
+ WebAPIAuthenticator auth = new WebAPIAuthenticator(wire,
+ descriptor, username, password);
+ WebAPIClient client = new WebAPIClient(descriptor, auth, wire);
+ return client;
+
+ } catch (URISyntaxException e) {
+ getLog().error("Bad URI (" + serviceURI + ")", e);
+ } catch (IOException e) {
+ getLog().error("Unable to connect to service (" + serviceURI + ")",
+ e);
+ }
+ // some kind of exception
+ return null;
+ }
+
+ protected TemplateDocument fileNameToTemplateDocument(WebAPIClient client, File tempFile)
+ throws IOException {
+ String templateName = fileToTemplateName(tempFile);//.obj
+ TemplateDocument doc = client.createTemplate(templateName);
+ return doc;
+ }
+
+ protected String fileToTemplateName(File tempFile) {
+ return tempFile.getName().substring(0, tempFile.getName().length() - 4);
+ }
+
+ protected int dirNameToTemplateNumber(File candidate)
+ throws MojoExecutionException {
+ int n = -188;
+ String num = candidate.getName().substring(TEMPLATE_PREFIX.length());
+ try {
+ n = Integer.parseInt(num);
+ } catch (NumberFormatException e) {
+ throw new MojoExecutionException("Badly formed template name in populate directory:"+candidate.getName());
+ }
+ return n;
+
+ }
+
+}
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-05 22:32:42 UTC (rev 370)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-05 23:18:49 UTC (rev 371)
@@ -1,223 +1,163 @@
package com.ogoglio.plugin;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import nanoxml.XMLElement;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
-import com.agical.rmock.core.util.StringUtils;
-import com.ogoglio.client.WebAPIAuthenticator;
import com.ogoglio.client.WebAPIClient;
-import com.ogoglio.client.WebAPIClientWire;
-import com.ogoglio.client.WebAPIDescriptor;
import com.ogoglio.util.StreamUtils;
import com.ogoglio.xml.PossessionDocument;
import com.ogoglio.xml.SpaceDocument;
import com.ogoglio.xml.TemplateDocument;
+import com.ogoglio.xml.ThingDocument;
/**
* @goal populate
*/
-public class PopulateMojo extends AbstractMojo {
- /**
- * @parameter
- */
- private File baseDir;
- /**
- * @parameter
- */
- private String serviceURI;
- /**
- * @parameter
- */
- private String username;
- /**
- * @parameter
- */
- private String password;
+public class PopulateMojo extends OgServiceMojoBase {
+ private HashMap<Long, Long> templateIdMap = new HashMap<Long, Long>();
- private HashMap<Long,Long> templateIdMap = new HashMap<Long,Long>();
- private List<SpaceDocument> spaces=new ArrayList<SpaceDocument>();
-
- private static final String TEMPLATE_PREFIX="template-";
- private static final String SPACE_PREFIX="space-";
+ private List<SpaceDocument> spaces = new ArrayList<SpaceDocument>();
- public void execute() throws MojoExecutionException {
- if (baseDir==null) {
- getLog().info("No populate baseDir given. No population done.");
- return;
- }
-
- if ((!baseDir.exists()) || (!baseDir.isDirectory()) || (!baseDir.canRead())) {
- getLog().error("Unable to access base dir:"+baseDir.getAbsolutePath());
- return;
- }
-
- if (serviceURI==null) {
- getLog().info("No populate serviceURI given. No population done.");
- return;
- }
-
- try {
- WebAPIClientWire wire=new WebAPIClientWire();
- WebAPIDescriptor descriptor=new WebAPIDescriptor(new URI(serviceURI));
- WebAPIAuthenticator auth=new WebAPIAuthenticator(wire,descriptor,username,password);
- WebAPIClient client=new WebAPIClient(descriptor,auth,wire);
- //we are now ready to upload
-
- File[] templates = baseDir.listFiles();
-
- for (int i=0; i<templates.length;++i) {
- File candidate=templates[i];
- if (candidate.getName().startsWith(TEMPLATE_PREFIX)) {
- uploadTemplate(client,candidate);
- } else if (candidate.getName().startsWith(SPACE_PREFIX)) {
- readSpace(client,candidate);
- } else {
- if (!candidate.getName().equals(".svn")) {
- getLog().warn("Unable to process in populate:"+candidate.getAbsolutePath());
- }
- }
- }
-
- patchSpaces(client);
-
- } catch (URISyntaxException e) {
- throw new MojoExecutionException("Bad URI syntax("+serviceURI+")",e);
- } catch (IOException e) {
- throw new MojoExecutionException("IO Exception (possibly auth?"+username+","+password+")",e);
- }
- }
+ public void execute() throws MojoExecutionException {
+ WebAPIClient client = validateArgsAndConnect();
- private void patchSpaces(WebAPIClient client) throws MojoExecutionException {
- SpaceDocument fakeSpaceDoc,realSpaceDoc;
-
- for (int i=0; i<spaces.size();++i) {
- fakeSpaceDoc=spaces.get(i);
- try {
- realSpaceDoc = client.createSpace(fakeSpaceDoc.getDisplayName());
- TemplateDocument templates[] = fakeSpaceDoc.getTemplateDocuments();
- for (int j=0; j<templates.length;++j) {
- long trueId = templateIdMap.get(new Long(templates[j].getTemplateID())).longValue();
- PossessionDocument possDoc = client.createPossession(trueId);
- client.addPossessionToSpace(possDoc.getPossessionID(), fakeSpaceDoc.getSpaceID());
- TemplateDocument realTemplateDoc=client.getTemplateDocument(username, trueId);
- getLog().info("Added Template "+realTemplateDoc.getDisplayName()+" to space "+realSpaceDoc.getDisplayName());
- }
- //client.setSpacePublished(realSpaceDoc.getSpaceID(), fakeSpaceDoc.getSpacePublished());
- long realSpaceID = realSpaceDoc.getSpaceID();
- client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
- client.setSpaceMaxGuests(realSpaceID, fakeSpaceDoc.getMaxGuests());
- client.setSpaceDisplayName(realSpaceID, fakeSpaceDoc.getDisplayName());
- client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
- } catch (IOException e) {
- throw new MojoExecutionException("IOException patching space ("+fakeSpaceDoc.getDisplayName()+":"+fakeSpaceDoc.getSpaceID()+")",e);
- }
- }
-
- }
+ File[] templates = populateDir.listFiles();
- private void readSpace(WebAPIClient client, File candidate) throws MojoExecutionException{
- String name = candidate.getName();
- String num= name.substring(SPACE_PREFIX.length());
- int spaceFakeId=-189;
- try {
- spaceFakeId = Integer.parseInt(num);
- } catch (NumberFormatException e) {
- getLog().error("Badly formed space name:"+name+". Ignoring.");
- }
- if (spaceFakeId==-189) {
- return;
- }
- try {
- FileInputStream inputStream = new FileInputStream(candidate);
- String docContent = StreamUtils.readInput(inputStream);
- SpaceDocument doc=new SpaceDocument(XMLElement.parseElementFromString(docContent));
- spaces.add(doc);
- inputStream.close();
- } catch (IOException e) {
- throw new MojoExecutionException("IO Error reading space",e);
- }
-
-
- }
+ for (int i = 0; i < templates.length; ++i) {
+ File candidate = templates[i];
+ if (candidate.getName().startsWith(TEMPLATE_PREFIX)) {
+ uploadTemplate(client, candidate);
+ } else if (candidate.getName().startsWith(SPACE_PREFIX)) {
+ readSpace(client, candidate);
+ } else {
+ if (!candidate.getName().equals(".svn")) {
+ getLog().warn("Unable to process in populate:" + candidate.getAbsolutePath());
+ }
+ }
+ }
- private void uploadTemplate(WebAPIClient client, File candidate) throws MojoExecutionException{
- String name = candidate.getName();
- String num= name.substring(TEMPLATE_PREFIX.length());
+ patchSpaces(client);
+ }
- int templateFakeId=-188;
- try {
- templateFakeId = Integer.parseInt(num);
- } catch (NumberFormatException e) {
- getLog().error("Badly formed template name:"+name+". Ignoring.");
- }
- if (templateFakeId==-188) {
- return;
- }
- getLog().info("Uploading template #"+templateFakeId+" to "+serviceURI);
- File[] objs=candidate.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".obj");
- }
- });
- if (objs.length!=1) {
- throw new MojoExecutionException("Badly formed directory "+name+". Should have 1 obj file but has "+objs.length);
- }
- try {
- String templateName=objs[0].getName();
- InputStream objStream=new FileInputStream(objs[0]);
- TemplateDocument doc = client.createTemplate(templateName.substring(0,templateName.length()-4));//.obj
- client.uploadTemplateGeometryStream(username,doc.getTemplateID(),0,objStream);
+ private void patchSpaces(WebAPIClient client) throws MojoExecutionException {
+ SpaceDocument fakeSpaceDoc, realSpaceDoc;
- templateIdMap.put(new Long(templateFakeId), new Long(doc.getTemplateID()));
- getLog().info("Created template from "+objs[0].getName()+
- " ["+templateFakeId+" -> "+doc.getTemplateID()+"]");
-
- File[] notObjs=candidate.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !name.endsWith(".obj");
- }
- });
- for (int i=0; i<notObjs.length; ++i) {
- File supportFile = notObjs[i];
- String supportName = supportFile.getName();
- if (supportFile.getName().endsWith(".js")) {
- String script = StreamUtils.readInput(new FileInputStream(supportFile));
- client.updateTemplateScript(username, doc.getTemplateID(), script);
- getLog().info("Uploaded script file:"+supportName);
- } else {
- if ((!(supportName.endsWith(".gif"))) && (!(supportName.endsWith(".jpg"))) &&
- (!(supportName.endsWith(".png"))) && (!(supportName.endsWith(".mtl")))) {
-
- if ((!(supportName.endsWith(".blend"))) && (!(supportName.endsWith(".3DS"))) &&
- (!(supportName.endsWith(".txt"))) && (!(supportName.equals(".svn")))) {
- getLog().warn("Don't know what to do with file "+supportName+". Ignoring.");
- }
- continue;
- }
- FileInputStream supportStream = new FileInputStream(supportFile);
- client.uploadTemplateResourceStream(username, doc.getTemplateID(), supportName, supportStream);
- getLog().info("Uploaded support file:"+supportName);
- }
- }
-
- } catch (IOException e) {
- throw new MojoExecutionException("IO Error in upload",e);
- }
- }
+ for (int i = 0; i < spaces.size(); ++i) {
+ fakeSpaceDoc = spaces.get(i);
+ try {
+ realSpaceDoc = client.createSpace(fakeSpaceDoc.getDisplayName());
+ ThingDocument things[] = fakeSpaceDoc.getThingDocuments();
+ for (int j = 0; j < things.length; ++j) {
+ ThingDocument thing = things[j];
+ PossessionDocument possDoc = client.createPossession(templateIdMap.get(thing.getTemplateID()));
+ possDoc = client.addPossessionToSpace(possDoc.getPossessionID(), realSpaceDoc.getSpaceID());
+ ThingDocument newThingDoc = client.getThingDocument(realSpaceDoc.getSpaceID(), possDoc.getThingID());
+ newThingDoc.setOrientation(thing.getOrientation());
+ newThingDoc.setTranslation(thing.getTranslation());
+ newThingDoc.setSplinePath(thing.getSplinePath());
+ newThingDoc.setScale(thing.getScale());
+ client.updateThing(realSpaceDoc.getSpaceID(), newThingDoc);
+ }
+ long realSpaceID = realSpaceDoc.getSpaceID();
+ client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
+ client.setSpaceMaxGuests(realSpaceID, fakeSpaceDoc.getMaxGuests());
+ client.setSpaceDisplayName(realSpaceID, fakeSpaceDoc.getDisplayName());
+ client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
+ getLog().info("Patched up space "+realSpaceDoc.getDisplayName());
+
+ } catch (IOException e) {
+ throw new MojoExecutionException("IOException patching space (" + fakeSpaceDoc.getDisplayName() + ":" + fakeSpaceDoc.getSpaceID() + ")", e);
+ }
+ }
+
+ }
+
+ private void readSpace(WebAPIClient client, File candidate) throws MojoExecutionException {
+ String name = candidate.getName();
+ String num = name.substring(SPACE_PREFIX.length());
+ int spaceFakeId = -189;
+ try {
+ spaceFakeId = Integer.parseInt(num);
+ } catch (NumberFormatException e) {
+ getLog().error("Badly formed space name:" + name + ". Ignoring.");
+ }
+ if (spaceFakeId == -189) {
+ return;
+ }
+ try {
+ FileInputStream inputStream = new FileInputStream(candidate);
+ String docContent = StreamUtils.readInput(inputStream);
+ SpaceDocument doc = new SpaceDocument(XMLElement.parseElementFromString(docContent));
+ spaces.add(doc);
+ inputStream.close();
+ } catch (IOException e) {
+ throw new MojoExecutionException("IO Error reading space", e);
+ }
+
+ }
+
+ private void uploadTemplate(WebAPIClient client, File candidate) throws MojoExecutionException {
+ String name = candidate.getName();
+ int templateFakeId = dirNameToTemplateNumber(candidate);
+
+ getLog().info("Uploading template #" + templateFakeId + " to " + serviceURI);
+ File[] objs = candidate.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".obj");
+ }
+ });
+ if (objs.length != 1) {
+ throw new MojoExecutionException("Badly formed directory " + name + ". Should have 1 obj file but has " + objs.length);
+ }
+ try {
+ TemplateDocument doc = fileNameToTemplateDocument(client, objs[0]);
+
+ InputStream objStream = new FileInputStream(objs[0]);
+ client.uploadTemplateGeometryStream(username, doc.getTemplateID(), 0, objStream);
+
+ templateIdMap.put(new Long(templateFakeId), new Long(doc.getTemplateID()));
+ getLog().info("Created template from " + objs[0].getName() + " [" + templateFakeId + " -> " + doc.getTemplateID() + "]");
+
+ File[] notObjs = candidate.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return !name.endsWith(".obj");
+ }
+ });
+ for (int i = 0; i < notObjs.length; ++i) {
+ File supportFile = notObjs[i];
+ String supportName = supportFile.getName();
+ if (supportFile.getName().endsWith(".js")) {
+ String script = StreamUtils.readInput(new FileInputStream(supportFile));
+ client.updateTemplateScript(username, doc.getTemplateID(), script);
+ getLog().info("Uploaded script file:" + supportName);
+ } else {
+ if ((!(supportName.endsWith(".gif"))) && (!(supportName.endsWith(".jpg"))) && (!(supportName.endsWith(".png"))) && (!(supportName.endsWith(".mtl")))) {
+
+ if ((!(supportName.endsWith(".blend"))) && (!(supportName.endsWith(".3DS"))) && (!(supportName.endsWith(".txt"))) && (!(supportName.equals(".svn")))) {
+ getLog().warn("Don't know what to do with file " + supportName + ". Ignoring.");
+ }
+ continue;
+ }
+ FileInputStream supportStream = new FileInputStream(supportFile);
+ client.uploadTemplateResourceStream(username, doc.getTemplateID(), supportName, supportStream);
+ getLog().info("Uploaded support file:" + supportName);
+ }
+ }
+
+ } catch (IOException e) {
+ throw new MojoExecutionException("IO Error in upload", e);
+ }
+ }
+
}
\ No newline at end of file
Added: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java (rev 0)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java 2007-09-05 23:18:49 UTC (rev 371)
@@ -0,0 +1,158 @@
+package com.ogoglio.plugin;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.HashMap;
+
+import nanoxml.XMLElement;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.util.StreamUtils;
+import com.ogoglio.xml.SpaceDocument;
+import com.ogoglio.xml.TemplateDocument;
+import com.ogoglio.xml.ThingDocument;
+
+/**
+ * @goal reverse
+ */
+public class ReverseMojo extends OgServiceMojoBase {
+ /**
+ * @parameter
+ */
+ private File reverseFile;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ WebAPIClient client = validateArgsAndConnect();
+ HashMap<String,Long> displayNameToLocalId = new HashMap<String, Long>();
+ HashMap<Long,Long> remoteIdTolocalId = new HashMap<Long, Long>();
+
+ long localThingId=1,localPossId=1;
+
+ if (client==null) {
+ return;
+ }
+
+ if (reverseFile==null) {
+ getLog().info("No reverse file configured. Mojo ignored.");
+ return;
+ }
+
+ if ((!reverseFile.isFile()) || (!reverseFile.canRead())) {
+ throw new MojoExecutionException("Can't read reverse file "+reverseFile.getAbsolutePath());
+ }
+
+ SpaceDocument origSpaceDoc = buildTemplateMaps(displayNameToLocalId,
+ remoteIdTolocalId);
+
+ int localSpaceId=getNextLocalSpaceId();
+
+ SpaceDocument result = rewhackSpaceDocument(remoteIdTolocalId,
+ localThingId, localPossId, origSpaceDoc, localSpaceId);
+
+ try {
+ writeSpaceDoc(result,localSpaceId);
+ } catch (IOException e) {
+ throw new MojoExecutionException(e,"IOException","can't write output file");
+ }
+ }
+
+ private SpaceDocument rewhackSpaceDocument(
+ HashMap<Long, Long> remoteIdTolocalId, long localThingId,
+ long localPossId, SpaceDocument origSpaceDoc, int localSpaceId) {
+ SpaceDocument result = new SpaceDocument(localSpaceId,origSpaceDoc.getDisplayName(),origSpaceDoc.getOwnerUsername(),
+ true /*origSpaceDoc.getPublished()*/,origSpaceDoc.getMaxGuests(),origSpaceDoc.getDisplaySea(),
+ origSpaceDoc.getSeaLevel(),origSpaceDoc.getSimID());
+
+ ThingDocument[] things=origSpaceDoc.getThingDocuments();
+ for (int i=0; i<things.length;++i) {
+ ThingDocument remoteThing=things[i];
+ ThingDocument localThing=new ThingDocument(localThingId++,remoteThing.getDisplayName(),
+ remoteIdTolocalId.get(new Long(remoteThing.getTemplateID())).longValue(),
+ remoteThing.getTemplateOwner(),remoteThing.getOwnerUsername(),
+ localPossId++, remoteThing.getTransform(),remoteThing.getSplinePath());
+ result.addThingDocument(localThing);
+ getLog().info("Fixed thing "+localThing.getDisplayName());
+ }
+ return result;
+ }
+
+ private SpaceDocument buildTemplateMaps(
+ HashMap<String, Long> displayNameToLocalId,
+ HashMap<Long, Long> remoteIdTolocalId)
+ throws MojoExecutionException, MojoFailureException {
+ SpaceDocument origSpaceDoc=null;
+ try {
+ String revContent = StreamUtils.readInput(new FileInputStream(reverseFile));
+ origSpaceDoc = new SpaceDocument(XMLElement.parseElementFromString(revContent));
+ } catch (IOException e) {
+ throw new MojoExecutionException(e,"IOException","Can't read space document "+reverseFile.getAbsolutePath());
+ }
+ File[] templateDirs= populateDir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.startsWith(TEMPLATE_PREFIX);
+ }
+ });
+ File[] objectFiles=new File[templateDirs.length];
+ for (int i=0; i< templateDirs.length;++i) {
+ File[] objs = templateDirs[i].listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".obj");
+ }
+ });
+ if (objs.length!=1) {
+ throw new MojoExecutionException("Directory "+templateDirs[i].getName()+" has wrong number of object files:"+objs.length);
+ }
+ objectFiles[i]=objs[0];
+ }
+ for (int i=0; i<objectFiles.length;++i) {
+ String tName = fileToTemplateName(objectFiles[i]);
+ int num = dirNameToTemplateNumber(objectFiles[i].getParentFile());
+ displayNameToLocalId.put(tName,new Long(num));
+ }
+ TemplateDocument[] mentioned = origSpaceDoc.getTemplateDocuments();
+ for (int i=0; i<mentioned.length;++i) {
+ TemplateDocument candidate = mentioned[i];
+ String remoteDisplayName = candidate.getDisplayName();
+ if (!displayNameToLocalId.containsKey(remoteDisplayName)) {
+ throw new MojoFailureException("Can't find a local template with display name "+remoteDisplayName);
+ }
+ Long local=displayNameToLocalId.get(remoteDisplayName);
+ remoteIdTolocalId.put(new Long(candidate.getTemplateID()), local);
+ getLog().info("Mapped "+remoteDisplayName+" ["+candidate.getTemplateID()+" ->"+local+"]");
+ }
+ return origSpaceDoc;
+ }
+
+ private void writeSpaceDoc(SpaceDocument result, int localSpaceId) throws IOException {
+ FileWriter wr=new FileWriter(new File(populateDir,SPACE_PREFIX+localSpaceId));
+ wr.write(result.toString());
+ wr.close();
+ getLog().info("Wrote new space document:"+(SPACE_PREFIX+localSpaceId));
+ }
+
+ private int getNextLocalSpaceId() throws MojoExecutionException {
+ int attempt=1,TOO_BIG=500;
+ File f;
+ do {
+ attempt++;
+ f=new File(populateDir,SPACE_PREFIX+(attempt));
+ //sanity
+ if (attempt==TOO_BIG) {
+ break;
+ }
+ } while (f.exists());
+ if (attempt==TOO_BIG) {
+ throw new MojoExecutionException("Don't know why but there are way too many space documents...aborting at "+attempt);
+ }
+ return attempt-1;
+ }
+
+}
Modified: maven/trunk/ogoglio-server/pom.xml
===================================================================
--- maven/trunk/ogoglio-server/pom.xml 2007-09-05 22:32:42 UTC (rev 370)
+++ maven/trunk/ogoglio-server/pom.xml 2007-09-05 23:18:49 UTC (rev 371)
@@ -190,7 +190,7 @@
</webResources>
</configuration>
</plugin>
- <!-- Our plugin config for building templates -->
+ <!-- Our plugin config for building templates and doing stuffing of data -->
<plugin>
<groupId>com.ogoglio</groupId>
<artifactId>og-plugin</artifactId>
@@ -201,7 +201,8 @@
<serviceURI>${ogoglio.baseURL}</serviceURI>
<username>${ogoglio.bootstrapUser}</username>
<password>${ogoglio.bootstrapUserPW}</password>
- <baseDir>src/main/resources/populate</baseDir>
+ <populateDir>src/main/resources/populate</populateDir>
+ <reverseFile>/tmp/reverse.xml</reverseFile>
<goalPrefix>og</goalPrefix>
</configuration>
Modified: maven/trunk/ogoglio-server/src/main/resources/populate/space-1
===================================================================
--- maven/trunk/ogoglio-server/src/main/resources/populate/space-1 2007-09-05 22:32:42 UTC (rev 370)
+++ maven/trunk/ogoglio-server/src/main/resources/populate/space-1 2007-09-05 23:18:49 UTC (rev 371)
@@ -1,201 +1,52 @@
<space ownerusername="library" sealevel="0.0" simid="1"
- displayname="Tech Office Space" maxguests="0" displaysea="false"
- spaceid="1" published="false">
- <thing templateid="42" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
- scalez="1.0" displayname="TV" scaley="1.0" templateowner="library"
- scalex="1.0" possessionid="2" thingid="2" z="10.0" y="0.0" x="0.0"
- ownerusername="library">
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.005" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Tube.001_Tube.002" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.001" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.002_Mesh" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.003" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Tube_Tube.001" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Sphere_Sphere.001" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.002" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.004" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- </thing>
- <thing templateid="28" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
- scalez="1.0" displayname="WhiteBoard" scaley="1.0"
- templateowner="library" scalex="1.0" possessionid="3" thingid="4"
- z="-10.0" y="0.0" x="0.0" ownerusername="library">
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.003" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube" scaley="1.0" scalex="1.0" z="0.0" y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.002" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.004" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.001" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <page rz="-0.0" ry="1.0" width="4.0" pageid="1" rx="0.0"
- rw="0.0" scalez="1.0" scaley="1.0" scalex="1.0"
- contenttype="text/plain" z="0.1" y="2.0" x="0.0" height="2.0" />
- </thing>
- <thing templateid="21" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
- scalez="1.0" displayname="memex" scaley="1.0" templateowner="library"
- scalex="1.0" possessionid="1" thingid="1" z="0.0" y="0.0" x="-10.0"
- ownerusername="library">
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.008_Black" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.001_Cube.002" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.003" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.010" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.005_Cube.001" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.008" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube" scaley="1.0" scalex="1.0" z="0.0" y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.004" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.009" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.004_Cube.005" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.007" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.005" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.003_Cube.004" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.001" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.012_Cube.010" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.002_Cube.003" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.011_Cube.006" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.006" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.010_Black.002" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.009_Black.001" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cylinder.002" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.007_Metal" scaley="1.0" scalex="1.0" z="0.0" y="0.0"
- x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Cube.006_Cube.007" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- </thing>
- <thing templateid="25" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
- scalez="1.0" displayname="OfficeDesk" scaley="1.0"
- templateowner="library" scalex="1.0" possessionid="4" thingid="3"
- z="0.0" y="0.0" x="10.0" ownerusername="library">
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="drawer2_07_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="ChamferBox_02_-_Defau" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="feet_02_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="drawer3_02_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Object07_02_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="long_drawe_01_-_Defau" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="drawer4_02_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="Object07_03_-_Default" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- <shape rz="0.0" ry="0.0" rx="0.0" rw="1.0" scalez="1.0"
- shapename="large_draw_02_-_Defau" scaley="1.0" scalex="1.0" z="0.0"
- y="0.0" x="0.0" />
- </thing>
- <template ownerusername="library" templateid="28"
- displayname="WhiteBoard">
- <scriptfile
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- <geometry levelofdetail="0"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- <supportfile filename="WhiteBoard.mtl"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- </template>
- <template ownerusername="library" templateid="42"
- displayname="TV">
- <scriptfile
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:23 PM PDT" />
- <geometry levelofdetail="0"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:23 PM PDT" />
- <supportfile filename="TV.mtl"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- </template>
- <template ownerusername="library" templateid="25"
- displayname="OfficeDesk">
- <supportfile filename="OfficeDesk.mtl"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- <geometry levelofdetail="0"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:24 PM PDT" />
- </template>
- <template ownerusername="library" templateid="21"
- displayname="memex">
- <geometry levelofdetail="0"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:23 PM PDT" />
- <supportfile filename="memex.mtl"
- lastmodifiedUTC="Tuesday, September 4, 2007 7:01:23 PM PDT" />
- </template>
-</space>
\ No newline at end of file
+ displayname="Sitting" maxguests="0" displaysea="false" spaceid="1"
+ published="true">
+ <thing templateid="9" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="EamesLoungeChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="1" thingid="1"
+ z="-5.0" y="0.0" x="-18.0" ownerusername="library" />
+ <thing templateid="24" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="OfficeChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="2" thingid="2"
+ z="-5.0" y="0.0" x="-15.0" ownerusername="library" />
+ <thing templateid="18" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="LeCorbusierRecliner" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="3" thingid="3"
+ z="-5.0" y="0.0" x="-9.0" ownerusername="library" />
+ <thing templateid="19" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="LeCorbusierSofa" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="4" thingid="4"
+ z="-5.0" y="0.0" x="-12.0" ownerusername="library" />
+ <thing templateid="16" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="JacobsenChair3107" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="5" thingid="5"
+ z="-5.0" y="0.0" x="-3.0" ownerusername="library" />
+ <thing templateid="5" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="CescaArmChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="6" thingid="6"
+ z="-5.0" y="0.0" x="-6.0" ownerusername="library" />
+ <thing templateid="8" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="AluminumChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="7" thingid="7"
+ z="-5.0" y="0.0" x="0.0" ownerusername="library" />
+ <thing templateid="20" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="MarshmallowSofa" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="8" thingid="8"
+ z="-5.0" y="0.0" x="3.0" ownerusername="library" />
+ <thing templateid="17" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="LeCorbusierArmChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="9" thingid="9"
+ z="-5.0" y="0.0" x="9.0" ownerusername="library" />
+ <thing templateid="3" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="BarcelonaChair" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="10" thingid="10"
+ z="-5.0" y="0.0" x="6.0" ownerusername="library" />
+ <thing templateid="31" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="OfficeChairNoArms" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="11" thingid="11"
+ z="-5.0" y="0.0" x="12.0" ownerusername="library" />
+ <thing templateid="6" rz="0.0" ry="0.0" rx="0.0" rw="1.0"
+ scalez="1.0" displayname="CornerSofa" scaley="1.0"
+ templateowner="library" scalex="1.0" possessionid="12" thingid="12"
+ z="-5.0" y="0.0" x="12.0" ownerusername="library" />
+</space>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|