|
From: <tre...@us...> - 2007-10-02 02:28:37
|
Revision: 467
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=467&view=rev
Author: trevorolio
Date: 2007-10-01 19:28:41 -0700 (Mon, 01 Oct 2007)
Log Message:
-----------
THIS CHECKIN REQUIRES A DB DROP
Introducing a new world of user configurable body settings. Ditched the old BodyRecord and created three new record types:
BodyDataRecords: hold information about the wadges of data which make up a body's base (e.g. mesh, morphs, textures...)
BodyConfigurationRecords: a user level representation of a body configuration, with a display name and a set of...
BodySettingRecords: morph interpolation values for a given body configuration (e.g. height, 0.9 or chin width, 0.2)
Halfway through documentifying and RESTifying these records. I can smell the day when this is autogenerated from annotated classes.
Modified Paths:
--------------
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountPersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountRecord.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/SpaceServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/xml/server/DocumentFactory.java
maven/trunk/ogoglio-server/src/main/resources/hibernate/migration-1.xml
maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java
Added Paths:
-----------
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyConfigurationRecord.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyDataRecord.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodySettingRecord.java
Removed Paths:
-------------
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyRecord.java
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountPersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountPersistTasks.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountPersistTasks.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -61,16 +61,6 @@
}
}
- if (document.getDefaultBodyID() != -1) {
- Query bodyQuery = hibernateSession.getNamedQuery(BodyPersistTasks.BODY_BY_ID);
- bodyQuery.setLong("bodyID", document.getDefaultBodyID());
- BodyRecord bodyRec = (BodyRecord) bodyQuery.uniqueResult();
- if (bodyRec != null && bodyRec.getOwnerUsername().equals(record.getUsername())) {
- dirty = true;
- record.setDefaultBodyID(document.getDefaultBodyID());
- }
- }
-
if (document.getFrozenUntil() != null) {
if (record.getFrozenUntil() != document.getFrozenUntil().getTime()) {
dirty = true;
@@ -150,11 +140,7 @@
record = new AccountRecord(username, accountlevel, email);
hibernateSession.save(record);
- BodyRecord bodyRec = new BodyRecord("Body", record.getUsername());
- hibernateSession.save(bodyRec);
- record.setDefaultBodyID(bodyRec.getBodyID());
- hibernateSession.update(record);
return record;
}
};
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountRecord.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/AccountRecord.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -43,8 +43,6 @@
private long frozenUntil = AccountDocument.NO_TIME_VALUE;
- private long defaultBodyId = 1;
-
public AccountRecord() {
}
@@ -234,14 +232,14 @@
setPasswordHash(null);
return true;
}
- if(cleanPassword(password) == null){
+ if (cleanPassword(password) == null) {
return false;
}
setPasswordHash(encode(password));
return true;
}
-
- public boolean isValidPassword(String password){
+
+ public boolean isValidPassword(String password) {
if (password == null || passwordHash == null || password.trim().length() == 0 || cleanPassword(password) == null) {
return false;
}
@@ -249,7 +247,7 @@
}
//TODO make this salt with some service-specific string
- private String encode(String plaintext){
+ private String encode(String plaintext) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(plaintext.getBytes("UTF-8"));
@@ -274,14 +272,6 @@
this.username = username;
}
- public long getDefaultBodyID() {
- return defaultBodyId;
- }
-
- public void setDefaultBodyID(long defaultBodyID) {
- this.defaultBodyId = defaultBodyID;
- }
-
public void setNotFrozen() {
this.frozenUntil = AccountDocument.NO_TIME_VALUE;
}
Added: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyConfigurationRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyConfigurationRecord.java (rev 0)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyConfigurationRecord.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -0,0 +1,58 @@
+package com.ogoglio.persist;
+
+import com.ogoglio.util.ArgumentUtils;
+
+public class BodyConfigurationRecord {
+
+ private long bodyConfigurationID = -1;
+
+ private String ownerUsername = null;
+
+ private String displayName = null;
+
+ private long bodyDataID = -1;
+
+ public BodyConfigurationRecord(){
+ }
+
+ public BodyConfigurationRecord(String ownerUsername, String displayName, long bodyDataID){
+ ArgumentUtils.assertNotEmpty(ownerUsername);
+ this.ownerUsername = ownerUsername;
+ ArgumentUtils.assertNotEmpty(displayName);
+ this.displayName = displayName;
+ ArgumentUtils.assertNotNegative(bodyDataID);
+ this.bodyDataID = bodyDataID;
+ }
+
+ public long getBodyConfigurationID() {
+ return bodyConfigurationID;
+ }
+
+ public void setBodyConfigurationID(long bodyConfigurationID) {
+ this.bodyConfigurationID = bodyConfigurationID;
+ }
+
+ public String getOwnerUsername() {
+ return ownerUsername;
+ }
+
+ public void setOwnerUsername(String ownerUsername) {
+ this.ownerUsername = ownerUsername;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public long getBodyDataID() {
+ return bodyDataID;
+ }
+
+ public void setBodyDataID(long bodyDataID) {
+ this.bodyDataID = bodyDataID;
+ }
+}
Added: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyDataRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyDataRecord.java (rev 0)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyDataRecord.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -0,0 +1,47 @@
+package com.ogoglio.persist;
+
+import com.ogoglio.util.ArgumentUtils;
+
+public class BodyDataRecord {
+
+ private long bodyDataID = -1;
+
+ private String displayName = null;
+
+ private String fileName = null;
+
+ public BodyDataRecord() {
+ }
+
+ public BodyDataRecord(String displayName, String fileName) {
+ ArgumentUtils.assertNotEmpty(displayName);
+ this.displayName = displayName;
+ ArgumentUtils.assertNotEmpty(fileName);
+ this.fileName = fileName;
+ }
+
+ public long getBodyDataID() {
+ return bodyDataID;
+ }
+
+ public void setBodyDataID(long bodyDataID) {
+ this.bodyDataID = bodyDataID;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+}
Deleted: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -1,165 +0,0 @@
-/* Copyright 2007 Transmutable (http://transmutable.com/)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-package com.ogoglio.persist;
-
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-
-import com.ogoglio.appdev.persist.HibernateTask;
-import com.ogoglio.appdev.persist.PersistException;
-import com.ogoglio.xml.BodyDocument;
-
-public class BodyPersistTasks {
-
- public static final String BODY_BY_ID = "com.ogoglio.persist.bodyByID";
-
- public static final String BODIES_BY_USERNAME = "com.ogoglio.persist.bodiesByUsername";
-
- public static BodyRecord[] findBodyByUsername(final String username, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- Query query = session.getNamedQuery(BODIES_BY_USERNAME);
- query.setString("username", username);
- return query.list().toArray(new BodyRecord[0]);
- }
- };
- task.setSessionFactory(sessionFactory);
- return (BodyRecord[]) task.execute();
- }
-
- public static BodyDocument update(final BodyRecord record, final BodyDocument bodyDoc, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- boolean dirty = false;
- if (bodyDoc.getDisplayName() != null && !bodyDoc.getDisplayName().equals(record.getDisplayName())) {
- dirty = true;
- record.setDisplayName(bodyDoc.getDisplayName());
- }
- if (bodyDoc.getHairIndex() != record.getHairIndex()) {
- dirty = true;
- record.setHairIndex(bodyDoc.getHairIndex());
- }
- if (bodyDoc.getEyesIndex() != record.getEyesIndex()) {
- dirty = true;
- record.setEyesIndex(bodyDoc.getEyesIndex());
- }
- if (bodyDoc.getNoseIndex() != record.getNoseIndex()) {
- dirty = true;
- record.setNoseIndex(bodyDoc.getNoseIndex());
- }
- if (bodyDoc.getMouthIndex() != record.getMouthIndex()) {
- dirty = true;
- record.setMouthIndex(bodyDoc.getMouthIndex());
- }
- if (bodyDoc.getFaceIndex() != record.getFaceIndex()) {
- dirty = true;
- record.setFaceIndex(bodyDoc.getFaceIndex());
- }
- if (bodyDoc.isMale() != record.isMale()) {
- dirty = true;
- record.setMale(bodyDoc.isMale());
- }
- if(bodyDoc.getHeight() != record.getHeight()){
- dirty = true;
- record.setHeight(bodyDoc.getHeight());
- }
- if(bodyDoc.getGirth() != record.getGirth()){
- dirty = true;
- record.setGirth(bodyDoc.getGirth());
- }
- if (dirty) {
- session.update(record);
- }
- return new BodyDocument(record.getBodyID(), record.getOwnerUsername(), record.getDisplayName(), record.getHairIndex(), record.getEyesIndex(), record.getNoseIndex(), record.getMouthIndex(), record.getFaceIndex(), record.isMale(), record.getHeight(), record.getGirth());
- }
- };
- task.setSessionFactory(sessionFactory);
- return (BodyDocument) task.execute();
- }
-
- public static BodyRecord[] findAllBodies(SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session hibernateSession) {
- Query query = hibernateSession.getNamedQuery("com.ogoglio.persist.bodies");
- return query.list().toArray(new BodyRecord[0]);
- }
- };
- task.setSessionFactory(sessionFactory);
- return (BodyRecord[]) task.execute();
- }
-
-
- public static void update(final BodyRecord record, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- session.update(record);
- return record;
- }
- };
- task.setSessionFactory(sessionFactory);
- task.execute();
- }
-
- //body records are also created in AccountPersistTasks.createAccount
- public static BodyRecord createBody(final String displayName, final String ownerUsername, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- Query accountQuery = session.getNamedQuery(AccountPersistTasks.ACCOUNT_BY_USERNAME);
- accountQuery.setString("username", ownerUsername);
- AccountRecord accountRecord = (AccountRecord) accountQuery.uniqueResult();
- if (accountRecord == null) {
- return null;
- }
- BodyRecord record = new BodyRecord(displayName, ownerUsername);
- session.save(record);
- return record;
- }
- };
- task.setSessionFactory(sessionFactory);
- return (BodyRecord) task.execute();
- }
-
- public static boolean delete(final BodyRecord record, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- Query accountQuery = session.getNamedQuery(AccountPersistTasks.ACCOUNT_BY_USERNAME);
- accountQuery.setString("username", record.getOwnerUsername());
- AccountRecord accountRecord = (AccountRecord) accountQuery.uniqueResult();
- if (accountRecord == null) {
- return null;
- }
- if (accountRecord.getDefaultBodyID() == record.getBodyID()) {
- return Boolean.FALSE;
- }
- session.delete(record);
- return Boolean.TRUE;
- }
- };
- task.setSessionFactory(sessionFactory);
- return task.execute() == Boolean.TRUE;
- }
-
- public static BodyRecord findBodyByID(final long bodyID, SessionFactory sessionFactory) throws PersistException {
- HibernateTask task = new HibernateTask() {
- public Object run(Session session) throws PersistException {
- Query query = session.getNamedQuery(BODY_BY_ID);
- query.setLong("bodyID", bodyID);
- return query.uniqueResult();
- }
- };
- task.setSessionFactory(sessionFactory);
- return (BodyRecord) task.execute();
- }
-}
Added: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java (rev 0)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyPersistTasks.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -0,0 +1,185 @@
+package com.ogoglio.persist;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import com.ogoglio.appdev.persist.HibernateTask;
+import com.ogoglio.appdev.persist.PersistException;
+
+public class BodyPersistTasks {
+
+ public static final String BODY_DATA = "com.ogoglio.persist.bodyData";
+
+ public static final String BODY_DATA_BY_ID = "com.ogoglio.persist.bodyDataByID";
+
+ public static final String BODY_DATA_BY_FILE_NAME = "com.ogoglio.persist.bodyDataByFileName";
+
+ public static final String BODY_CONFIGURATION_BY_USERNAME_AND_BODY_DATA_ID = "com.ogoglio.persist.bodyConfigurationByUsernameAndBodyDataID";
+
+ public static final String BODY_CONFIGURATION_BY_USERNAME = "com.ogoglio.persist.bodyConfigurationByUsername";
+
+ public static final String BODY_CONFIGURATION_BY_ID = "com.ogoglio.persist.bodyConfigurationByID";
+
+ public static final String BODY_SETTINGS_BY_CONFIGURATION_ID = "com.ogoglio.persist.bodySettingsByConfigurationID";
+
+ public static final String BODY_SETTING_BY_CONFIGURATION_ID_AND_SETTING_NAME = "com.ogoglio.persist.bodySettingByConfigurationIDAndSettingName";
+
+ public static BodySettingRecord createOrUpdateBodySetting(final long bodyConfigurationID, final String settingName, final float setting, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_SETTING_BY_CONFIGURATION_ID_AND_SETTING_NAME);
+ query.setLong("bodyConfigurationID", bodyConfigurationID);
+ query.setString("settingName", settingName);
+
+ if (setting < 0 || setting > 1) {
+ return null;
+ }
+
+ BodySettingRecord record = (BodySettingRecord) query.uniqueResult();
+ if (record != null) {
+ if (Math.abs(setting - record.getSetting()) < 0.0001) {
+ return record;
+ }
+ record.setSetting(setting);
+ return record;
+ }
+
+ Query configQuery = session.getNamedQuery(BODY_CONFIGURATION_BY_ID);
+ configQuery.setLong("bodyConfigurationID", bodyConfigurationID);
+ BodyConfigurationRecord configRecord = (BodyConfigurationRecord) configQuery.uniqueResult();
+ if (configRecord == null) {
+ return null;
+ }
+
+ record = new BodySettingRecord(bodyConfigurationID, settingName, setting);
+ session.save(record);
+ return record;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodySettingRecord) task.execute();
+ }
+
+ public static BodyConfigurationRecord findOrCreateBodyConfiguration(final String username, final long bodyDataID, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_CONFIGURATION_BY_USERNAME_AND_BODY_DATA_ID);
+ query.setString("username", username);
+ query.setLong("bodyDataID", bodyDataID);
+
+ BodyConfigurationRecord record = (BodyConfigurationRecord) query.uniqueResult();
+ if (record != null) {
+ return record;
+ }
+
+ record = new BodyConfigurationRecord(username, "New Body", bodyDataID);
+ session.save(record);
+ return record;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyConfigurationRecord) task.execute();
+ }
+
+ public static BodyConfigurationRecord[] findBodyConfigurationByUsername(final String username, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_CONFIGURATION_BY_USERNAME);
+ query.setString("username", username);
+ return query.list().toArray(new BodyConfigurationRecord[0]);
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyConfigurationRecord[]) task.execute();
+ }
+
+ public static BodyConfigurationRecord findBodyConfigurationByID(final long bodyConfigurationID, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_CONFIGURATION_BY_ID);
+ query.setLong("bodyConfigurationID", bodyConfigurationID);
+ return query.uniqueResult();
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyConfigurationRecord) task.execute();
+ }
+
+ public static BodySettingRecord[] findBodySettingsByConfigurationID(final long bodyConfigurationID, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_SETTINGS_BY_CONFIGURATION_ID);
+ query.setLong("bodyConfigurationID", bodyConfigurationID);
+ return query.list().toArray(new BodySettingRecord[0]);
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodySettingRecord[]) task.execute();
+ }
+
+ public static BodyDataRecord findBodyDataRecord(final String fileName, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_DATA_BY_FILE_NAME);
+ query.setString("fileName", fileName);
+ return query.uniqueResult();
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyDataRecord) task.execute();
+ }
+
+ public static BodyDataRecord findOrCreateBodyDataRecord(final String displayName, final String fileName, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_DATA_BY_FILE_NAME);
+ query.setString("fileName", fileName);
+ BodyDataRecord record = (BodyDataRecord) query.uniqueResult();
+ if (record != null) {
+ return record;
+ }
+
+ record = new BodyDataRecord(displayName, fileName);
+ session.save(record);
+ return record;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyDataRecord) task.execute();
+ }
+
+ public static BodyDataRecord findBodyDataByID(final long bodyDataID, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_DATA_BY_ID);
+ query.setLong("bodyDataID", bodyDataID);
+ return query.uniqueResult();
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyDataRecord) task.execute();
+ }
+
+ public static boolean deleteBodyData(final BodyDataRecord bodyDataRecord, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ session.delete(bodyDataRecord);
+ return Boolean.TRUE;
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return Boolean.TRUE.equals(task.execute());
+ }
+
+ public static BodyDataRecord[] findAllBodyDataRecords(SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session session) throws PersistException {
+ Query query = session.getNamedQuery(BODY_DATA);
+ return query.list().toArray(new BodyDataRecord[0]);
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (BodyDataRecord[]) task.execute();
+ }
+}
Deleted: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyRecord.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodyRecord.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -1,152 +0,0 @@
-/* Copyright 2007 Transmutable (http://transmutable.com/)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-package com.ogoglio.persist;
-
-import com.ogoglio.util.ArgumentUtils;
-
-public class BodyRecord {
-
- private long bodyID = -1;
-
- private String displayName = null;
-
- private String ownerUsername = null;
-
- private int hairIndex = 0, eyesIndex = 0, noseIndex = 0, mouthIndex = 0, faceIndex = 0;
-
- private float girth = 1;
-
- private float height = 2;
-
- private boolean male = true;
-
- public BodyRecord() {
- }
-
- public BodyRecord(String displayName, String ownerUsername) {
- ArgumentUtils.assertNotNull(displayName);
- this.displayName = displayName;
-
- ArgumentUtils.assertNotNull(ownerUsername);
- this.ownerUsername = ownerUsername;
- }
-
- public float getGirth() {
- return girth;
- }
-
- public void setGirth(float girth) {
- this.girth = girth;
- }
-
- public float getHeight() {
- return height;
- }
-
- public void setHeight(float height) {
- this.height = height;
- }
-
- public boolean isMale() {
- return male;
- }
-
- public void setMale(boolean male) {
- this.male = male;
- }
-
- public int getEyesIndex() {
- return eyesIndex;
- }
-
- public void setEyesIndex(int eyesIndex) {
- ArgumentUtils.assertNotNegative(eyesIndex);
- this.eyesIndex = eyesIndex;
- }
-
- public int getFaceIndex() {
- return faceIndex;
- }
-
- public void setFaceIndex(int faceIndex) {
- ArgumentUtils.assertNotNegative(faceIndex);
- this.faceIndex = faceIndex;
- }
-
- public int getHairIndex() {
- return hairIndex;
- }
-
- public void setHairIndex(int hairIndex) {
- ArgumentUtils.assertNotNegative(hairIndex);
- this.hairIndex = hairIndex;
- }
-
- public boolean getMale() {
- return male;
- }
- public int getMouthIndex() {
- return mouthIndex;
- }
-
- public void setMouthIndex(int mouthIndex) {
- ArgumentUtils.assertNotNegative(mouthIndex);
- this.mouthIndex = mouthIndex;
- }
-
- public int getNoseIndex() {
- return noseIndex;
- }
-
- public void setNoseIndex(int noseIndex) {
- ArgumentUtils.assertNotNegative(noseIndex);
- this.noseIndex = noseIndex;
- }
-
- public long getBodyID() {
- return bodyID;
- }
-
- public void setBodyID(long bodyID) {
- this.bodyID = bodyID;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getOwnerUsername() {
- return ownerUsername;
- }
-
- public void setOwnerUsername(String ownerUsername) {
- this.ownerUsername = ownerUsername;
- }
-
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof BodyRecord)) {
- return false;
- }
- return getBodyID() == ((BodyRecord) obj).getBodyID();
- }
-
- public int hashCode() {
- return ("BodyRecord-" + getBodyID()).hashCode();
- }
-
-}
Added: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodySettingRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodySettingRecord.java (rev 0)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/BodySettingRecord.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -0,0 +1,61 @@
+package com.ogoglio.persist;
+
+import com.ogoglio.util.ArgumentUtils;
+
+public class BodySettingRecord {
+
+ private long bodySettingID = -1;
+
+ private long bodyConfigurationID = -1;
+
+ private String settingName = null;
+
+ private float setting = -1;
+
+ public BodySettingRecord(){
+ }
+
+ public BodySettingRecord(long configurationID, String settingName, float setting){
+ ArgumentUtils.assertNotNegative(configurationID);
+ this.bodyConfigurationID = configurationID;
+ ArgumentUtils.assertNotEmpty(settingName);
+ this.settingName = settingName;
+ ArgumentUtils.assertNotNegative(setting);
+ if(setting > 1){
+ setting = 1;
+ }
+ this.setting = setting;
+ }
+
+ public long getBodySettingID() {
+ return bodySettingID;
+ }
+
+ public void setBodySettingID(long bodySettingID) {
+ this.bodySettingID = bodySettingID;
+ }
+
+ public long getBodyConfigurationID() {
+ return bodyConfigurationID;
+ }
+
+ public void setBodyConfigurationID(long bodyConfigurationID) {
+ this.bodyConfigurationID = bodyConfigurationID;
+ }
+
+ public String getSettingName() {
+ return settingName;
+ }
+
+ public void setSettingName(String settingName) {
+ this.settingName = settingName;
+ }
+
+ public float getSetting() {
+ return setting;
+ }
+
+ public void setSetting(float setting) {
+ this.setting = setting;
+ }
+}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -66,7 +66,7 @@
} else if (message.getPayload() instanceof PayloadFactory.AuthenticatedPayload) {
PayloadFactory.AuthenticatedPayload payload = (PayloadFactory.AuthenticatedPayload) message.getPayload();
- spaceSim.userAuthenticated(payload.getUsername(), payload.getBodyID());
+ spaceSim.userAuthenticated(payload.getUsername());
} else if (message.getPayload() instanceof PayloadFactory.LoggedOutPayload) {
PayloadFactory.LoggedOutPayload payload = (PayloadFactory.LoggedOutPayload) message.getPayload();
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -43,10 +43,8 @@
import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.BlockingQueue;
import com.ogoglio.util.Log;
-import com.ogoglio.util.UIConstants;
import com.ogoglio.util.BlockingQueue.QueueClosedException;
import com.ogoglio.viewer.j3d.J3DRenderer;
-import com.ogoglio.xml.BodyDocument;
import com.ogoglio.xml.DoorDocument;
import com.ogoglio.xml.PageDocument;
import com.ogoglio.xml.SettingDocument;
@@ -158,10 +156,6 @@
public InputStream getPageContentStream(long thingID, long pageID) {
return null; //we don't need to render pages, do we?
}
-
- public BodyDocument getBodyDocument(String username, long bodyID) throws IOException {
- return new BodyDocument(bodyID, username, "Body", 0, 0, 0, 0, 0, false, 2, 1);
- }
}
public synchronized void cleanup() {
@@ -743,8 +737,8 @@
return results;
}
- public void userAuthenticated(String username, long bodyID) {
- userCounts.incrementUserCount(username, bodyID);
+ public void userAuthenticated(String username) {
+ userCounts.incrementUserCount(username);
Log.info(username + " logged into " + space.getSpaceID() + ": " + space.getDisplayName());
}
@@ -792,19 +786,18 @@
}
}
- synchronized int incrementUserCount(String username, long bodyID) {
+ synchronized int incrementUserCount(String username) {
Integer count = (Integer) map.get(username);
if (count == null) {
count = new Integer(1);
Transform3D position = new Transform3D();
position.setTranslation(new Vector3d(0, 0, 0));
- User user = new User(space, username, position, bodyID);
+ User user = new User(space, username, position);
space.addUser(user);
SpaceEvent spaceEvent = new SpaceEvent(SpaceEvent.ADD_USER_EVENT);
spaceEvent.setProperty(SpaceEvent.USERNAME, username);
spaceEvent.setPointAndOrientationData(user.getPosition());
- spaceEvent.setProperty(SpaceEvent.BODY_ID, new Long(bodyID));
handleSpaceEvent(spaceEvent);
} else {
count = new Integer(count.intValue() + 1);
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -14,7 +14,6 @@
package com.ogoglio.site;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
@@ -28,7 +27,6 @@
import nanoxml.XMLElement;
import com.ogoglio.appdev.persist.PersistException;
-import com.ogoglio.appdev.servlet.DescendingSiteResource;
import com.ogoglio.appdev.servlet.Four04SiteResource;
import com.ogoglio.appdev.servlet.SiteResource;
import com.ogoglio.client.WebAPIClientWire;
@@ -37,11 +35,8 @@
import com.ogoglio.mail.MailFormatter;
import com.ogoglio.mail.MailSendException;
import com.ogoglio.mail.MailTemplateFactory;
-import com.ogoglio.media.MediaService;
import com.ogoglio.persist.AccountPersistTasks;
import com.ogoglio.persist.AccountRecord;
-import com.ogoglio.persist.BodyPersistTasks;
-import com.ogoglio.persist.BodyRecord;
import com.ogoglio.persist.PendingEmailValidationRecord;
import com.ogoglio.persist.PendingEmailValidationTasks;
import com.ogoglio.persist.PossessionPersistTasks;
@@ -55,11 +50,8 @@
import com.ogoglio.persist.SpaceRecord;
import com.ogoglio.persist.TemplatePersistTasks;
import com.ogoglio.persist.TemplateRecord;
-import com.ogoglio.sim.Sim;
import com.ogoglio.util.Log;
-import com.ogoglio.util.StreamUtils;
import com.ogoglio.xml.AccountDocument;
-import com.ogoglio.xml.BodyDocument;
import com.ogoglio.xml.PossessionDocument;
import com.ogoglio.xml.ServiceStateDocument;
import com.ogoglio.xml.TemplateDocument;
@@ -82,9 +74,9 @@
AccountDocument result = null;
if (authed) {
- result = new AccountDocument(account.getUsername(), account.getAccountlevel(), account.getFirstName(), account.getLastName(), account.getHomepage(), null, account.getEmail(), account.getCreationDate(), null, account.getFrozenUntil(), account.getDefaultBodyID());
+ result = new AccountDocument(account.getUsername(), account.getAccountlevel(), account.getFirstName(), account.getLastName(), account.getHomepage(), null, account.getEmail(), account.getCreationDate(), null, account.getFrozenUntil());
} else {
- result = new AccountDocument(account.getUsername(), null, null, null, null, null, null, account.getCreationDate(), null, account.getFrozenUntil(), account.getDefaultBodyID());
+ result = new AccountDocument(account.getUsername(), null, null, null, null, null, null, account.getCreationDate(), null, account.getFrozenUntil());
}
return result;
}
@@ -213,7 +205,6 @@
private class AccountResource extends AuthenticatedSiteResource {
public AccountResource() {
super(SiteResource.WILDCARD_ELEMENT, true, getSessionFactory());
- addSubResource(new BodiesResource());
addSubResource(new SpacesResource());
addSubResource(new TemplatesResource());
addSubResource(new MembershipResource());
@@ -650,238 +641,5 @@
}
}
- private class BodyGeometryResource extends DescendingSiteResource {
- public BodyGeometryResource() {
- super("geometry");
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
- String usernameParam = pathElements[1];
- try {
- AccountRecord authedAccount = AuthServlet.getAuthedAccountRecord(request, getSessionFactory());
- if (authedAccount == null) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (!requestedAccount.getUsername().equals(authedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- long bodyID = Long.parseLong(pathElements[3]);
- BodyRecord record = BodyPersistTasks.findBodyByID(bodyID, getSessionFactory());
- if (record == null || !record.getOwnerUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (pathElements.length == 5) {
- response.setStatus(HttpServletResponse.SC_OK);
- return;
- } else if ("data".equals(pathElements[pathElements.length - 1])) {
- getMediaService().write(MediaService.getBodyGeometryName(bodyID), request.getInputStream(), Sim.MAX_GEOMETRY_SIZE);
- } else {
- getMediaService().write(MediaService.getBodyResourceName(bodyID, pathElements[pathElements.length - 1]), request.getInputStream(), Sim.MAX_GEOMETRY_RESOURCE_SIZE);
- }
- response.setStatus(HttpServletResponse.SC_OK);
- return;
- } catch (PersistException e) {
- e.printStackTrace();
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
- String usernameParam = pathElements[1];
- try {
- AccountRecord authedAccount = AuthServlet.getAuthedAccountRecord(request, getSessionFactory());
- if (authedAccount == null) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- long bodyID = Long.parseLong(pathElements[3]);
- BodyRecord record = BodyPersistTasks.findBodyByID(bodyID, getSessionFactory());
- if (record == null || !record.getOwnerUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (pathElements.length == 5) {
- sendStringResponse("This is where a geometry document would be.", "text/plain", response);
- return;
- }
-
- InputStream data = null;
- if ("data".equals(pathElements[pathElements.length - 1])) {
- data = getMediaService().getData(MediaService.getBodyGeometryName(bodyID));
- } else {
- data = getMediaService().getData(MediaService.getBodyResourceName(bodyID, pathElements[pathElements.length - 1]));
- }
- if (data == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
- response.setStatus(HttpServletResponse.SC_OK);
- StreamUtils.write(data, response.getOutputStream());
- } catch (PersistException e) {
- e.printStackTrace();
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- return;
- }
- }
- }
-
- private class BodyResource extends AuthenticatedSiteResource {
- public BodyResource() {
- super(SiteResource.LONG_ELEMENT, false, getSessionFactory());
- addSubResource(new BodyGeometryResource());
- }
-
- public void doDelete(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
- String usernameParam = pathElements[1];
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (authedAccount == null || !authedAccount.getUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- long bodyID = Long.parseLong(pathElements[pathElements.length - 1]);
- BodyRecord record = BodyPersistTasks.findBodyByID(bodyID, getSessionFactory());
- if (record == null || !record.getOwnerUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (BodyPersistTasks.delete(record, getSessionFactory()) == true) {
- response.setStatus(HttpServletResponse.SC_OK);
- } else {
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
- String usernameParam = pathElements[1];
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (authedAccount == null || !authedAccount.getUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- long bodyID = Long.parseLong(pathElements[pathElements.length - 1]);
- BodyRecord record = BodyPersistTasks.findBodyByID(bodyID, getSessionFactory());
- if (record == null || !record.getOwnerUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (!requestedAccount.getUsername().equals(record.getOwnerUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- BodyDocument bodyDoc = new BodyDocument(parseXML(request.getInputStream()));
- bodyDoc = BodyPersistTasks.update(record, bodyDoc, getSessionFactory());
- if (bodyDoc != null) {
- sendStringResponse(bodyDoc.toString(), "text/xml", response);
- } else {
- response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- }
- }
-
- public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
- String usernameParam = pathElements[1];
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- long bodyID = Long.parseLong(pathElements[pathElements.length - 1]);
- BodyRecord record = BodyPersistTasks.findBodyByID(bodyID, getSessionFactory());
- if (record == null || !record.getOwnerUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- BodyDocument doc = DocumentFactory.documentFromRecord(record);
- sendStringResponse(doc.toString(), "text/xml", response);
- }
- }
-
- private class BodiesResource extends AuthenticatedSiteResource {
-
- public BodiesResource() {
- super("body", true, getSessionFactory());
- addSubResource(new BodyResource());
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
- String usernameParam = pathElements[pathElements.length - 2];
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (!authedAccount.getUsername().equals(requestedAccount.getUsername())) {
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
-
- XMLElement bodyElement = parseXML(request.getInputStream());
- String displayName = bodyElement.getStringAttribute(BodyDocument.DISPLAY_NAME);
- BodyRecord bodyRecord = BodyPersistTasks.createBody(displayName, authedAccount.getUsername(), getSessionFactory());
- BodyDocument result = DocumentFactory.documentFromRecord(bodyRecord);
- response.setStatus(HttpServletResponse.SC_OK);
- response.setContentType("text/xml");
- response.getOutputStream().write(result.toString().getBytes());
- return;
- }
-
- public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
- String usernameParam = pathElements[pathElements.length - 2];
- AccountRecord requestedAccount = AccountPersistTasks.findAccountByUsername(usernameParam, getSessionFactory());
- if (requestedAccount == null) {
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- XMLElement result = new XMLElement("list");
-
- BodyRecord[] bodyRecords = BodyPersistTasks.findBodyByUsername(requestedAccount.getUsername(), getSessionFactory());
- for (int i = 0; i < bodyRecords.length; i++) {
- result.addChild(DocumentFactory.documentFromRecord(bodyRecords[i]).toElement());
- }
-
- response.setStatus(HttpServletResponse.SC_OK);
- response.setContentType("text/xml");
- response.getOutputStream().write(result.toString().getBytes());
- return;
- }
- }
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -124,7 +124,6 @@
}
String username = null;
- long bodyID = -1;
if (payload.getLoginCookie().startsWith(WebConstants.GUEST_COOKIE_PREFIX)) {
if (!SpacePersistTasks.canReadSpace(null, payload.getSpaceID(), sessionFactory)) {
Message failureMessage = new Message(channelServer.getLocator(), request.getOrigin(), payload.getSpaceID(), new PayloadFactory.AuthenticationFailurePayload("Guests are not allowed in this space."));
@@ -132,7 +131,6 @@
return;
}
username = payload.getLoginCookie();
- bodyID = -1;
} else {
AccountRecord accountRecord = AccountPersistTasks.findAccountByCookie(payload.getLoginCookie(), sessionFactory);
@@ -143,7 +141,6 @@
return;
}
username = accountRecord.getUsername();
- bodyID = accountRecord.getDefaultBodyID();
}
SpaceRecord spaceRecord = SpacePersistTasks.findSpaceBySpaceID(payload.getSpaceID(), sessionFactory);
@@ -193,7 +190,7 @@
Message message = new Message(channelServer.getLocator(), request.getOrigin(), payload.getSpaceID(), new PayloadFactory.AuthenticationSuccessPayload(username));
sourceChannel.sendMessage(message);
- Message simMessage = new Message(channelServer.getLocator(), request.getOrigin(), payload.getSpaceID(), new PayloadFactory.AuthenticatedPayload(username, bodyID));
+ Message simMessage = new Message(channelServer.getLocator(), request.getOrigin(), payload.getSpaceID(), new PayloadFactory.AuthenticatedPayload(username));
sendMessageToSpace(locatorAuth.simHost, locatorAuth.eventPort, locatorAuth.spaceID, simMessage);
return;
} else if (request.getPayload() instanceof PayloadFactory.LogoutPayload) {
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/SpaceServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/SpaceServlet.java 2007-10-02 02:28:36 UTC (rev 466)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/SpaceServlet.java 2007-10-02 02:28:41 UTC (rev 467)
@@ -33,6 +33,8 @@
import com.ogoglio.client.WebAPIUtil;
import com.ogoglio.media.MediaService;
import com.ogoglio.persist.AccountRecord;
+import com.ogoglio.persist.BodyDataRecord;
+import com.ogoglio.persist.BodyPersistTasks;
import com.ogoglio.persist.ServiceStateRecord;
import com.ogoglio.persist.ServiceStateTasks;
import com.ogoglio.persist.SimPersistTasks;
@@ -44,6 +46,7 @@
import com.ogoglio.sim.site.SimServlet;
import com.ogoglio.util.Log;
import com.ogoglio.xml.AccountDocument;
+import com.ogoglio.xml.BodyDataDocument;
import com.ogoglio.xml.ServiceDocument;
import com.ogoglio.xml.ServiceStateDocument;
import com.ogoglio.xml.SimDocument;
@@ -97,6 +100,7 @@
addSubResource(new SimResource());
addSubResource(new StateResource());
addSubResource(new SpaceResource());
+ addSubResource(new BodiesResource());
}
public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord authedAccount) throws PersistException, ServletException, IOException {
@@ -110,11 +114,11 @@
return;
}
String accountLevel = authedAccount.getAccountlevel();
- if(!AccountDocument.ACCOUNT_LEVEL_ADMIN.equals(accountLevel) && !AccountDocument.ACCOUNT_LEVEL_ADVANCED.equals(accountLevel) && !AccountDocument.ACCOUNT_LEVEL_PRO.equals(accountLevel)){
+ if (!AccountDocument.ACCOUNT_LEVEL_ADMIN.equals(accountLevel) && !AccountDocument.ACCOUNT_LEVEL_ADVANCED.equals(accountLevel) && !AccountDocument.ACCOUNT_LEVEL_PRO.equals(accountLevel)) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
-
+
XMLElement spaceElement = parseXML(request.getInputStream());
if (!SpaceDocument.NAME.equals(spaceElement.getName())) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@@ -135,6 +139,70 @@
}
}
+ private class BodiesResource extends AuthenticatedSiteResource {
+ public BodiesResource() {
+ super("body", false, getSessionFactory());
+ addSubResource(new BodyResource());
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord accountRecord) throws PersistException, IOException {
+ BodyDataRecord[] bodyDataRecords = BodyPersistTasks.findAllBodyDataRecords(getSessionFactory());
+ XMLElement listElement = new XMLElement("list");
+ for (int i = 0; i < bodyDataRecords.length; i++) {
+ listElement.addChild(DocumentFactory.documentFromRecord(bodyDataRecords[i]).toElement());
+ }
+ sendStringResponse(listElement.toString(), "text/xml", response);
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord accountRecord) throws PersistException, IOException {
+ if (accountRecord == null || !AccountDocument.ACCOUNT_LEVEL_ADMIN.equals(accountRecord.getAccountlevel())) {
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+
+ BodyDataDocument bodyDataDoc = new BodyDataDocument(parseXML(request.getInputStream()));
+ BodyDataRecord record = BodyPersistTasks.findOrCreateBodyDataRecord(bodyDataDoc.getDisplayName(), bodyDataDoc.getFileName(), getSessionFactory());
+ if (record == null) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ return;
+ }
+
+ sendStringResponse(DocumentFactory.documentFromRecord(record).toString(), "text/xml", response);
+ }
+ }
+
+ private class BodyResource extends AuthenticatedSiteResource {
+ public BodyResource() {
+ super(SiteResource.LONG_ELEMENT, false, getSessionFactory());
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord accountRecord) throws PersistException, IOException {
+ long bodyDataID = Long.parseLong(pathElements[pathElements.length - 1]);
+ BodyDataRecord bodyDataRecord = BodyPersistTasks.findBodyDataByID(bodyDataID, getSessionFactory());
+ if(bodyDataRecord == null){
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+ sendStringResponse(DocumentFactory.documentFromRecord(bodyDataRecord).toString(), "text/xml", response);
+ }
+
+ public void doDelete(HttpServletRequest request, HttpServletResponse response, String[] pathElements, AccountRecord accountRecord) throws PersistException, IOException {
+ long bodyDataID = Long.parseLong(pathElements[pathElements.length - 1]);
+ BodyDataRecord bodyDataRecord = BodyPersistTasks.findBodyDataByID(bodyDataID, getSessionFactory());
+ if(bodyDataRecord == null){
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
+ if(accountRecord == null || !AccountDocument.ACCOUNT_LEVEL_ADMIN.equals(accountRecord.getAccountlevel())){
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+ BodyPersistTasks.deleteBodyData(bodyDataRecord, getSessionFactory());
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+ }
+
private class StateResource extends AuthenticatedSiteResource {
public StateResource() {
super("state", false, getSessionFactory());
@@ -272,14 +340,14 @@
}
private boolean canUseMethodOnSpace(String method, AccountRecord authedAccount, SpaceRecord spaceRecord) throws PersistException {
- if(("HEAD".equals(method) || "GET".equals(method))){
+ if (("HEAD".equals(method) || "GET".equals(method))) {
return SpacePersistTasks.canReadSpac...
[truncated message content] |