http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbDeltaStoreUtil.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbDeltaStoreUtil.java b/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbDeltaStoreUtil.java deleted file mode 100644 index e93bfed..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbDeltaStoreUtil.java +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.persistence.mongodb; - -import com.google.common.collect.ImmutableList; -import com.google.protobuf.ByteString; -import com.google.protobuf.InvalidProtocolBufferException; - -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; - -import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer; -import org.waveprotocol.box.server.persistence.PersistenceException; -import org.waveprotocol.box.server.persistence.protos.ProtoDeltaStoreDataSerializer; -import org.waveprotocol.box.server.waveserver.ByteStringMessage; -import org.waveprotocol.box.server.waveserver.WaveletDeltaRecord; -import org.waveprotocol.wave.federation.Proto.ProtocolDocumentOperation; -import org.waveprotocol.wave.model.document.operation.DocOp; -import org.waveprotocol.wave.model.operation.wave.AddParticipant; -import org.waveprotocol.wave.model.operation.wave.BlipContentOperation; -import org.waveprotocol.wave.model.operation.wave.BlipOperation; -import org.waveprotocol.wave.model.operation.wave.NoOp; -import org.waveprotocol.wave.model.operation.wave.RemoveParticipant; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.operation.wave.WaveletBlipOperation; -import org.waveprotocol.wave.model.operation.wave.WaveletOperation; -import org.waveprotocol.wave.model.operation.wave.WaveletOperationContext; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * A utility class to serialize/deserialize delta objects to/from MongoDB. The - * implementation approach is analog to the provided at - * {@link CoreWaveletOperationSerializer} and - * {@link ProtoDeltaStoreDataSerializer} - * - * @author [email protected] (Pablo Ojanguren) - */ -public class MongoDbDeltaStoreUtil { - public static final String WAVELET_OP_WAVELET_BLIP_OPERATION = "WaveletBlipOperation"; - public static final String WAVELET_OP_REMOVE_PARTICIPANT = "RemoveParticipant"; - public static final String WAVELET_OP_ADD_PARTICIPANT = "AddParticipant"; - public static final String WAVELET_OP_NOOP = "NoOp"; - public static final String FIELD_BYTES = "bytes"; - public static final String FIELD_CONTENTOP = "contentop"; - public static final String FIELD_BLIPOP = "blipop"; - public static final String FIELD_BLIPID = "blipid"; - public static final String FIELD_PARTICIPANT = "participant"; - public static final String FIELD_TYPE = "type"; - public static final String FIELD_OPS = "ops"; - public static final String FIELD_APPLICATIONTIMESTAMP = "applicationtimestamp"; - public static final String FIELD_AUTHOR = "author"; - public static final String FIELD_ADDRESS = "address"; - public static final String FIELD_HISTORYHASH = "historyhash"; - public static final String FIELD_VERSION = "version"; - public static final String FIELD_TRANSFORMED_RESULTINGVERSION_VERSION = - "transformed.resultingversion.version"; - public static final String FIELD_TRANSFORMED_APPLIEDATVERSION = "transformed.appliedatversion"; - public static final String FIELD_TRANSFORMED_RESULTINGVERSION = "transformed.resultingversion"; - public static final String FIELD_APPLIEDATVERSION = "appliedatversion"; - public static final String FIELD_RESULTINGVERSION = "resultingversion"; - public static final String FIELD_TRANSFORMED = "transformed"; - public static final String FIELD_APPLIED = "applied"; - public static final String FIELD_WAVELET_ID = "waveletid"; - public static final String FIELD_WAVE_ID = "waveid"; - - public static DBObject serialize(WaveletDeltaRecord waveletDelta, String waveId, String waveletId) { - - BasicDBObject mongoWaveletDelta = new BasicDBObject(); - - mongoWaveletDelta.append(FIELD_WAVE_ID, waveId); - mongoWaveletDelta.append(FIELD_WAVELET_ID, waveletId); - - mongoWaveletDelta.append(FIELD_APPLIEDATVERSION, serialize(waveletDelta.getAppliedAtVersion())); - mongoWaveletDelta.append(FIELD_APPLIED, waveletDelta.getAppliedDelta().getByteArray()); - mongoWaveletDelta.append(FIELD_TRANSFORMED, serialize(waveletDelta.getTransformedDelta())); - - return mongoWaveletDelta; - } - - public static DBObject serialize(HashedVersion hashedVersion) { - BasicDBObject mongoHashedVersion = new BasicDBObject(); - mongoHashedVersion.append(FIELD_VERSION, hashedVersion.getVersion()); - mongoHashedVersion.append(FIELD_HISTORYHASH, hashedVersion.getHistoryHash()); - return mongoHashedVersion; - } - - public static DBObject serialize(ParticipantId participantId) { - BasicDBObject mongoParticipantId = new BasicDBObject(); - mongoParticipantId.append(FIELD_ADDRESS, participantId.getAddress()); - return mongoParticipantId; - } - - public static DBObject serialize(TransformedWaveletDelta transformedWaveletDelta) { - BasicDBObject mongoTransformedWaveletDelta = new BasicDBObject(); - mongoTransformedWaveletDelta.append(FIELD_AUTHOR, - serialize(transformedWaveletDelta.getAuthor())); - mongoTransformedWaveletDelta.append(FIELD_RESULTINGVERSION, - serialize(transformedWaveletDelta.getResultingVersion())); - mongoTransformedWaveletDelta.append(FIELD_APPLICATIONTIMESTAMP, - transformedWaveletDelta.getApplicationTimestamp()); - - mongoTransformedWaveletDelta.append(FIELD_APPLIEDATVERSION, - transformedWaveletDelta.getAppliedAtVersion()); - - BasicDBList mongoWaveletOperations = new BasicDBList(); - - for (WaveletOperation op : transformedWaveletDelta) { - mongoWaveletOperations.add(serialize(op)); - } - - mongoTransformedWaveletDelta.append(FIELD_OPS, mongoWaveletOperations); - - return mongoTransformedWaveletDelta; - } - - public static DBObject serialize(WaveletOperation waveletOp) { - final BasicDBObject mongoOp = new BasicDBObject(); - - if (waveletOp instanceof NoOp) { - mongoOp.append(FIELD_TYPE, WAVELET_OP_NOOP); - - } else if (waveletOp instanceof AddParticipant) { - mongoOp.append(FIELD_TYPE, WAVELET_OP_ADD_PARTICIPANT); - mongoOp.append(FIELD_PARTICIPANT, serialize(((AddParticipant) waveletOp).getParticipantId())); - - } else if (waveletOp instanceof RemoveParticipant) { - mongoOp.append(FIELD_TYPE, WAVELET_OP_REMOVE_PARTICIPANT); - mongoOp.append(FIELD_PARTICIPANT, - serialize(((RemoveParticipant) waveletOp).getParticipantId())); - } else if (waveletOp instanceof WaveletBlipOperation) { - final WaveletBlipOperation waveletBlipOp = (WaveletBlipOperation) waveletOp; - - mongoOp.append(FIELD_TYPE, WAVELET_OP_WAVELET_BLIP_OPERATION); - mongoOp.append(FIELD_BLIPID, waveletBlipOp.getBlipId()); - - if (waveletBlipOp.getBlipOp() instanceof BlipContentOperation) { - mongoOp.append(FIELD_BLIPOP, serialize((BlipContentOperation) waveletBlipOp.getBlipOp())); - } else { - throw new IllegalArgumentException("Unsupported blip operation: " - + waveletBlipOp.getBlipOp()); - } - } else { - throw new IllegalArgumentException("Unsupported wavelet operation: " + waveletOp); - } - return mongoOp; - } - - public static DBObject serialize(BlipContentOperation blipContentOp) { - BasicDBObject mongoBlipContentOp = new BasicDBObject(); - mongoBlipContentOp.append(FIELD_CONTENTOP, serialize(blipContentOp.getContentOp())); - return mongoBlipContentOp; - } - - public static DBObject serialize(DocOp docOp) { - BasicDBObject mongoDocOp = new BasicDBObject(); - mongoDocOp.append(FIELD_BYTES, CoreWaveletOperationSerializer.serialize(docOp).toByteArray()); - return mongoDocOp; - } - - public static WaveletDeltaRecord deserializeWaveletDeltaRecord(DBObject dbObject) - throws PersistenceException { - try { - return new WaveletDeltaRecord( - deserializeHashedVersion((DBObject) dbObject.get(FIELD_APPLIEDATVERSION)), - ByteStringMessage.parseProtocolAppliedWaveletDelta(ByteString.copyFrom((byte[]) dbObject - .get(FIELD_APPLIED))), - deserializeTransformedWaveletDelta((DBObject) dbObject.get(FIELD_TRANSFORMED))); - - } catch (InvalidProtocolBufferException e) { - throw new PersistenceException(e); - } - } - - public static HashedVersion deserializeHashedVersion(DBObject dbObject) { - return HashedVersion.of((Long) dbObject.get(FIELD_VERSION), - (byte[]) dbObject.get(FIELD_HISTORYHASH)); - } - - public static ParticipantId deserializeParicipantId(DBObject dbObject) { - return ParticipantId.ofUnsafe((String) dbObject.get(FIELD_ADDRESS)); - } - - public static TransformedWaveletDelta deserializeTransformedWaveletDelta(DBObject dbObject) - throws PersistenceException { - - ParticipantId author = deserializeParicipantId((DBObject) dbObject.get(FIELD_AUTHOR)); - HashedVersion resultingVersion = - deserializeHashedVersion((DBObject) dbObject.get(FIELD_RESULTINGVERSION)); - long applicationTimestamp = (Long) dbObject.get(FIELD_APPLICATIONTIMESTAMP); - - BasicDBList dbOps = (BasicDBList) dbObject.get(FIELD_OPS); - ImmutableList.Builder<WaveletOperation> operations = ImmutableList.builder(); - - int numOperations = dbOps.size(); - - // Code analog to ProtoDeltaStoreDataSerializer.deserialize - for (int i = 0; i < numOperations; i++) { - - WaveletOperationContext context; - if (i == numOperations - 1) { - context = new WaveletOperationContext(author, applicationTimestamp, 1, resultingVersion); - } else { - context = new WaveletOperationContext(author, applicationTimestamp, 1); - } - operations.add(deserializeWaveletOperation((DBObject) dbOps.get(i), context)); - } - - return new TransformedWaveletDelta(author, resultingVersion, applicationTimestamp, - operations.build()); - } - - public static WaveletOperation deserializeWaveletOperation(DBObject dbObject, - WaveletOperationContext context) throws PersistenceException { - String type = (String) dbObject.get(FIELD_TYPE); - if (type.equals(WAVELET_OP_NOOP)) { - return new NoOp(context); - } else if (type.equals(WAVELET_OP_ADD_PARTICIPANT)) { - return new AddParticipant(context, - deserializeParicipantId((DBObject) dbObject.get(FIELD_PARTICIPANT))); - } else if (type.equals(WAVELET_OP_REMOVE_PARTICIPANT)) { - return new RemoveParticipant(context, - deserializeParicipantId((DBObject) dbObject.get(FIELD_PARTICIPANT))); - } else if (type.equals(WAVELET_OP_WAVELET_BLIP_OPERATION)) { - return new WaveletBlipOperation((String) dbObject.get(FIELD_BLIPID), - deserializeBlipContentOperation((DBObject) dbObject.get(FIELD_BLIPOP), context)); - } else { - throw new IllegalArgumentException("Unsupported operation: " + type); - } - } - - public static BlipOperation deserializeBlipContentOperation(DBObject dbObject, - WaveletOperationContext context) throws PersistenceException { - return new BlipContentOperation(context, - deserializeDocOp((DBObject) dbObject.get(FIELD_CONTENTOP))); - } - - private static DocOp deserializeDocOp(DBObject dbObject) throws PersistenceException { - try { - return CoreWaveletOperationSerializer.deserialize(ProtocolDocumentOperation - .parseFrom(((byte[]) dbObject.get(FIELD_BYTES)))); - } catch (InvalidProtocolBufferException e) { - throw new PersistenceException(e); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java b/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java deleted file mode 100644 index 8ff53ca..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.persistence.mongodb; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; - -import com.mongodb.DB; -import com.mongodb.Mongo; -import com.mongodb.MongoClient; -import com.mongodb.MongoException; - -import org.waveprotocol.box.server.persistence.PersistenceStartException; -import org.waveprotocol.wave.util.logging.Log; - -import java.net.UnknownHostException; - -/** - * Class to lazily setup and manage the MongoDb connection. - * - * @author [email protected] (Lennard de Rijk) - * - */ -public class MongoDbProvider { - private static final Log LOG = Log.get(MongoDbProvider.class); - - private String dbHost; - - private String dbPort; - - private String dbName; - - /** - * Our {@link MongoClient} instance, should be accessed by getMongo unless during - * start(). - */ - private Mongo mongo; - - /** - * Lazily instantiated {@link MongoDbStore}. - */ - private MongoDbStore mongoDbStore; - - /** - * Separated store for Deltas {@link MongoDbDeltaStore} - */ - private MongoDbDeltaStore mongoDbDeltaStore; - - /** Stores whether we have successfully setup a live {@link Mongo} instance. */ - private boolean isRunning; - - /** - * Constructs a new empty {@link MongoDbProvider}. - */ - public MongoDbProvider(String dbHost, String dbPort, String dbName) { - this.dbHost = dbHost; - this.dbPort = dbPort; - this.dbName = dbName; - } - - /** - * Starts the {@link Mongo} instance and explicitly checks whether it is - * actually alive. - * - * @throws PersistenceStartException if we can't make a connection to MongoDb. - */ - private void start() { - Preconditions.checkState(!isRunning(), "Can't start after a connection has been established"); - - String host = dbHost; - int port = Integer.parseInt(dbPort); - try { - // New MongoDB Client, see http://docs.mongodb.org/manual/release-notes/drivers-write-concern/ - mongo = new MongoClient(host, port); - } catch (UnknownHostException e) { - throw new PersistenceStartException("Unable to resolve the MongoDb hostname", e); - } - - try { - // Check to see if we are alive - mongo.getDB(dbName).command("ping"); - } catch (MongoException e) { - throw new PersistenceStartException("Can't ping MongoDb", e); - } - - isRunning = true; - LOG.info("Started MongoDb persistence"); - } - - - /** - * Returns the {@link DB} with the name that is specified in the properties - * file. - */ - private DB getDatabase() { - return getDatabaseForName(dbName); - } - - /** - * Returns a {@link DB} instance for the database with the given name - * - * @param name the name of the database - */ - @VisibleForTesting - DB getDatabaseForName(String name) { - return getMongo().getDB(name); - } - - /** - * Return the {@link Mongo} instance that we are managing. - */ - private Mongo getMongo() { - if (!isRunning) { - start(); - } - return mongo; - } - - /** - * Returns true iff the {@link MongoDbProvider} is running. - */ - public boolean isRunning() { - return isRunning; - } - - /** - * Returns a {@link MongoDbStore} instance created from the settings in this - * provider. - */ - public MongoDbStore provideMongoDbStore() { - if (mongoDbStore == null) { - mongoDbStore = new MongoDbStore(getDatabase()); - } - return mongoDbStore; - } - - /** - * Returns a {@link MongoDbDeltaStore} instance created from the settings in this - * provider. - */ - public MongoDbDeltaStore provideMongoDbDeltaStore() { - if (mongoDbDeltaStore == null) { - mongoDbDeltaStore = new MongoDbDeltaStore(getDatabase()); - } - - return mongoDbDeltaStore; - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbStore.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbStore.java b/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbStore.java deleted file mode 100644 index c5a0087..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/persistence/mongodb/MongoDbStore.java +++ /dev/null @@ -1,433 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.persistence.mongodb; - -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.wave.api.Context; -import com.google.wave.api.ProtocolVersion; -import com.google.wave.api.event.EventType; -import com.google.wave.api.robot.Capability; - -import com.mongodb.BasicDBObject; -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.MongoException; -import com.mongodb.gridfs.GridFS; -import com.mongodb.gridfs.GridFSDBFile; -import com.mongodb.gridfs.GridFSInputFile; - -import org.bson.types.BasicBSONList; -import org.waveprotocol.box.attachment.AttachmentMetadata; -import org.waveprotocol.box.attachment.AttachmentProto; -import org.waveprotocol.box.attachment.proto.AttachmentMetadataProtoImpl; -import org.waveprotocol.box.server.account.AccountData; -import org.waveprotocol.box.server.account.HumanAccountData; -import org.waveprotocol.box.server.account.HumanAccountDataImpl; -import org.waveprotocol.box.server.account.RobotAccountData; -import org.waveprotocol.box.server.account.RobotAccountDataImpl; -import org.waveprotocol.box.server.authentication.PasswordDigest; -import org.waveprotocol.box.server.persistence.AccountStore; -import org.waveprotocol.box.server.persistence.AttachmentStore; -import org.waveprotocol.box.server.persistence.PersistenceException; -import org.waveprotocol.box.server.persistence.SignerInfoStore; -import org.waveprotocol.box.server.robots.RobotCapabilities; -import org.waveprotocol.wave.crypto.SignatureException; -import org.waveprotocol.wave.crypto.SignerInfo; -import org.waveprotocol.wave.federation.Proto.ProtocolSignerInfo; -import org.waveprotocol.wave.media.model.AttachmentId; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * <b>CertPathStore:</b><br/> - * <i>Collection(signerInfo):</i> - * <ul> - * <li>_id : signerId byte array.</li> - * <li>protoBuff : byte array representing the protobuff message of a - * {@link ProtocolSignerInfo}.</li> - * </ul> - * <p> - * - * @author [email protected] (Lennard de Rijk) - * @author [email protected] (Joseph Gentle) - * - */ -public final class MongoDbStore implements SignerInfoStore, AttachmentStore, AccountStore { - - private static final String ACCOUNT_COLLECTION = "account"; - private static final String ACCOUNT_HUMAN_DATA_FIELD = "human"; - private static final String ACCOUNT_ROBOT_DATA_FIELD = "robot"; - - private static final String HUMAN_PASSWORD_FIELD = "passwordDigest"; - - private static final String PASSWORD_DIGEST_FIELD = "digest"; - private static final String PASSWORD_SALT_FIELD = "salt"; - - private static final String ROBOT_URL_FIELD = "url"; - private static final String ROBOT_SECRET_FIELD = "secret"; - private static final String ROBOT_CAPABILITIES_FIELD = "capabilities"; - private static final String ROBOT_VERIFIED_FIELD = "verified"; - - private static final String CAPABILITIES_VERSION_FIELD = "version"; - private static final String CAPABILITIES_HASH_FIELD = "capabilitiesHash"; - private static final String CAPABILITIES_CAPABILITIES_FIELD = "capabilities"; - private static final String CAPABILITY_CONTEXTS_FIELD = "contexts"; - private static final String CAPABILITY_FILTER_FIELD = "filter"; - - private static final Logger LOG = Logger.getLogger(MongoDbStore.class.getName()); - - private final DB database; - private final GridFS attachmentGrid; - private final GridFS thumbnailGrid; - private final GridFS metadataGrid; - - MongoDbStore(DB database) { - this.database = database; - attachmentGrid = new GridFS(database, "attachments"); - thumbnailGrid = new GridFS(database, "thumbnails"); - metadataGrid = new GridFS(database, "metadata"); - } - - @Override - public void initializeSignerInfoStore() throws PersistenceException { - // Nothing to initialize - } - - @Override - public SignerInfo getSignerInfo(byte[] signerId) { - DBObject query = getDBObjectForSignerId(signerId); - DBCollection signerInfoCollection = getSignerInfoCollection(); - DBObject signerInfoDBObject = signerInfoCollection.findOne(query); - - // Sub-class contract specifies return null when not found - SignerInfo signerInfo = null; - - if (signerInfoDBObject != null) { - byte[] protobuff = (byte[]) signerInfoDBObject.get("protoBuff"); - try { - signerInfo = new SignerInfo(ProtocolSignerInfo.parseFrom(protobuff)); - } catch (InvalidProtocolBufferException e) { - LOG.log(Level.SEVERE, "Couldn't parse the protobuff stored in MongoDB: " + protobuff, e); - } catch (SignatureException e) { - LOG.log(Level.SEVERE, "Couldn't parse the certificate chain or domain properly", e); - } - } - return signerInfo; - } - - @Override - public void putSignerInfo(ProtocolSignerInfo protocolSignerInfo) throws SignatureException { - SignerInfo signerInfo = new SignerInfo(protocolSignerInfo); - byte[] signerId = signerInfo.getSignerId(); - - // Not using a modifier here because rebuilding the object is not a lot of - // work. Doing implicit upsert by using save with a DBOBject that has an _id - // set. - DBObject signerInfoDBObject = getDBObjectForSignerId(signerId); - signerInfoDBObject.put("protoBuff", protocolSignerInfo.toByteArray()); - getSignerInfoCollection().save(signerInfoDBObject); - } - - /** - * Returns an instance of {@link DBCollection} for storing SignerInfo. - */ - private DBCollection getSignerInfoCollection() { - return database.getCollection("signerInfo"); - } - - /** - * Returns a {@link DBObject} which contains the key-value pair used to - * signify the signerId. - * - * @param signerId the signerId value to set. - * @return a new {@link DBObject} with the (_id,signerId) entry. - */ - private DBObject getDBObjectForSignerId(byte[] signerId) { - DBObject query = new BasicDBObject(); - query.put("_id", signerId); - return query; - } - - // *********** Attachments. - - @Override - public AttachmentData getAttachment(AttachmentId attachmentId) { - - final GridFSDBFile attachment = attachmentGrid.findOne(attachmentId.serialise()); - return fileToAttachmentData(attachment); - } - - @Override - public void storeAttachment(AttachmentId attachmentId, InputStream data) - throws IOException { - saveFile(attachmentGrid.createFile(data, attachmentId.serialise())); - } - - @Override - public void deleteAttachment(AttachmentId attachmentId) { - attachmentGrid.remove(attachmentId.serialise()); - thumbnailGrid.remove(attachmentId.serialise()); - metadataGrid.remove(attachmentId.serialise()); - } - - - @Override - public AttachmentMetadata getMetadata(AttachmentId attachmentId) throws IOException { - final GridFSDBFile metadata = metadataGrid.findOne(attachmentId.serialise()); - - if (metadata == null) { - return null; - } - AttachmentProto.AttachmentMetadata protoMetadata = - AttachmentProto.AttachmentMetadata.parseFrom(metadata.getInputStream()); - return new AttachmentMetadataProtoImpl(protoMetadata); - } - - @Override - public AttachmentData getThumbnail(AttachmentId attachmentId) throws IOException { - final GridFSDBFile thumbnail = thumbnailGrid.findOne(attachmentId.serialise()); - return fileToAttachmentData(thumbnail); - } - - @Override - public void storeMetadata(AttachmentId attachmentId, AttachmentMetadata metaData) - throws IOException { - AttachmentMetadataProtoImpl proto = new AttachmentMetadataProtoImpl(metaData); - byte[] bytes = proto.getPB().toByteArray(); - GridFSInputFile file = - metadataGrid.createFile(new ByteArrayInputStream(bytes), attachmentId.serialise()); - saveFile(file); - } - - @Override - public void storeThumbnail(AttachmentId attachmentId, InputStream dataData) throws IOException { - saveFile(thumbnailGrid.createFile(dataData, attachmentId.serialise())); - } - - private void saveFile(GridFSInputFile file) throws IOException { - try { - file.save(); - } catch (MongoException e) { - // Unfortunately, file.save() wraps any IOException thrown in a - // 'MongoException'. Since the interface explicitly throws IOExceptions, - // we unwrap any IOExceptions thrown. - Throwable innerException = e.getCause(); - if (innerException instanceof IOException) { - throw (IOException) innerException; - } else { - throw e; - } - }; - } - - private AttachmentData fileToAttachmentData(final GridFSDBFile attachmant) { - if (attachmant == null) { - return null; - } else { - return new AttachmentData() { - - @Override - public InputStream getInputStream() throws IOException { - return attachmant.getInputStream(); - } - - @Override - public long getSize() { - return attachmant.getLength(); - } - }; - } - } - - // ******** AccountStore - - @Override - public void initializeAccountStore() throws PersistenceException { - // TODO: Sanity checks not handled by MongoDBProvider??? - } - - @Override - public AccountData getAccount(ParticipantId id) { - DBObject query = getDBObjectForParticipant(id); - DBObject result = getAccountCollection().findOne(query); - - if (result == null) { - return null; - } - - DBObject human = (DBObject) result.get(ACCOUNT_HUMAN_DATA_FIELD); - if (human != null) { - return objectToHuman(id, human); - } - - DBObject robot = (DBObject) result.get(ACCOUNT_ROBOT_DATA_FIELD); - if (robot != null) { - return objectToRobot(id, robot); - } - - throw new IllegalStateException("DB object contains neither a human nor a robot"); - } - - @Override - public void putAccount(AccountData account) { - DBObject object = getDBObjectForParticipant(account.getId()); - - if (account.isHuman()) { - object.put(ACCOUNT_HUMAN_DATA_FIELD, humanToObject(account.asHuman())); - } else if (account.isRobot()) { - object.put(ACCOUNT_ROBOT_DATA_FIELD, robotToObject(account.asRobot())); - } else { - throw new IllegalStateException("Account is neither a human nor a robot"); - } - - getAccountCollection().save(object); - } - - @Override - public void removeAccount(ParticipantId id) { - DBObject object = getDBObjectForParticipant(id); - getAccountCollection().remove(object); - } - - private DBObject getDBObjectForParticipant(ParticipantId id) { - DBObject query = new BasicDBObject(); - query.put("_id", id.getAddress()); - return query; - } - - private DBCollection getAccountCollection() { - return database.getCollection(ACCOUNT_COLLECTION); - } - - // ****** HumanAccountData serialization - - private DBObject humanToObject(HumanAccountData account) { - DBObject object = new BasicDBObject(); - - PasswordDigest digest = account.getPasswordDigest(); - if (digest != null) { - DBObject digestObj = new BasicDBObject(); - digestObj.put(PASSWORD_SALT_FIELD, digest.getSalt()); - digestObj.put(PASSWORD_DIGEST_FIELD, digest.getDigest()); - - object.put(HUMAN_PASSWORD_FIELD, digestObj); - } - - return object; - } - - private HumanAccountData objectToHuman(ParticipantId id, DBObject object) { - PasswordDigest passwordDigest = null; - - DBObject digestObj = (DBObject) object.get(HUMAN_PASSWORD_FIELD); - if (digestObj != null) { - byte[] salt = (byte[]) digestObj.get(PASSWORD_SALT_FIELD); - byte[] digest = (byte[]) digestObj.get(PASSWORD_DIGEST_FIELD); - passwordDigest = PasswordDigest.from(salt, digest); - } - - return new HumanAccountDataImpl(id, passwordDigest); - } - - // ****** RobotAccountData serialization - - private DBObject robotToObject(RobotAccountData account) { - return new BasicDBObject() - .append(ROBOT_URL_FIELD, account.getUrl()) - .append(ROBOT_SECRET_FIELD, account.getConsumerSecret()) - .append(ROBOT_CAPABILITIES_FIELD, capabilitiesToObject(account.getCapabilities())) - .append(ROBOT_VERIFIED_FIELD, account.isVerified()); - } - - private DBObject capabilitiesToObject(RobotCapabilities capabilities) { - if (capabilities == null) { - return null; - } - - BasicDBObject capabilitiesObj = new BasicDBObject(); - for (Capability capability : capabilities.getCapabilitiesMap().values()) { - BasicBSONList contexts = new BasicBSONList(); - for (Context c : capability.getContexts()) { - contexts.add(c.name()); - } - capabilitiesObj.put(capability.getEventType().name(), - new BasicDBObject() - .append(CAPABILITY_CONTEXTS_FIELD, contexts) - .append(CAPABILITY_FILTER_FIELD, capability.getFilter())); - } - - BasicDBObject object = - new BasicDBObject() - .append(CAPABILITIES_CAPABILITIES_FIELD, capabilitiesObj) - .append(CAPABILITIES_HASH_FIELD, capabilities.getCapabilitiesHash()) - .append(CAPABILITIES_VERSION_FIELD, capabilities.getProtocolVersion().name()); - - return object; - } - - private AccountData objectToRobot(ParticipantId id, DBObject robot) { - String url = (String) robot.get(ROBOT_URL_FIELD); - String secret = (String) robot.get(ROBOT_SECRET_FIELD); - RobotCapabilities capabilities = - objectToCapabilities((DBObject) robot.get(ROBOT_CAPABILITIES_FIELD)); - boolean verified = (Boolean) robot.get(ROBOT_VERIFIED_FIELD); - return new RobotAccountDataImpl(id, url, secret, capabilities, verified); - } - - @SuppressWarnings("unchecked") - private RobotCapabilities objectToCapabilities(DBObject object) { - if (object == null) { - return null; - } - - Map<String, Object> capabilitiesObj = - (Map<String, Object>) object.get(CAPABILITIES_CAPABILITIES_FIELD); - Map<EventType, Capability> capabilities = CollectionUtils.newHashMap(); - - for (Entry<String, Object> capability : capabilitiesObj.entrySet()) { - EventType eventType = EventType.valueOf(capability.getKey()); - List<Context> contexts = CollectionUtils.newArrayList(); - DBObject capabilityObj = (DBObject) capability.getValue(); - DBObject contextsObj = (DBObject) capabilityObj.get(CAPABILITY_CONTEXTS_FIELD); - for (String contextId : contextsObj.keySet()) { - contexts.add(Context.valueOf((String) contextsObj.get(contextId))); - } - String filter = (String) capabilityObj.get(CAPABILITY_FILTER_FIELD); - - capabilities.put(eventType, new Capability(eventType, contexts, filter)); - } - - String capabilitiesHash = (String) object.get(CAPABILITIES_HASH_FIELD); - ProtocolVersion version = - ProtocolVersion.valueOf((String) object.get(CAPABILITIES_VERSION_FIELD)); - - return new RobotCapabilities(capabilities, capabilitiesHash, version); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoAccountDataSerializer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoAccountDataSerializer.java b/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoAccountDataSerializer.java deleted file mode 100644 index 856aa93..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoAccountDataSerializer.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.persistence.protos; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.protobuf.ByteString; -import com.google.wave.api.Context; -import com.google.wave.api.ProtocolVersion; -import com.google.wave.api.event.EventType; -import com.google.wave.api.robot.Capability; - -import org.waveprotocol.box.server.account.AccountData; -import org.waveprotocol.box.server.account.HumanAccountData; -import org.waveprotocol.box.server.account.HumanAccountDataImpl; -import org.waveprotocol.box.server.account.RobotAccountData; -import org.waveprotocol.box.server.account.RobotAccountDataImpl; -import org.waveprotocol.box.server.authentication.PasswordDigest; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoAccountData; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoAccountData.AccountDataType; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoHumanAccountData; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoPasswordDigest; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoRobotAccountData; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoRobotCapabilities; -import org.waveprotocol.box.server.persistence.protos.ProtoAccountStoreData.ProtoRobotCapability; -import org.waveprotocol.box.server.robots.RobotCapabilities; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.util.List; -import java.util.Map; - -/** - * This class is used to serialize and deserialize {@link AccountData} and {@link ProtoAccountData} - * - * @author [email protected] (Tad Glines) - */ -public class ProtoAccountDataSerializer { - /** - * Serialize {@link AccountData} into {@link ProtoAccountData}. - */ - public static ProtoAccountData serialize(AccountData account) { - Preconditions.checkNotNull(account, "account is null"); - Preconditions.checkArgument(account.isHuman() || account.isRobot(), - "account is neither a human or robot account!"); - ProtoAccountData.Builder builder = ProtoAccountData.newBuilder(); - builder.setAccountId(account.getId().getAddress()); - if (account.isHuman()) { - builder.setAccountType(AccountDataType.HUMAN_ACCOUNT); - builder.setHumanAccountData(serialize(account.asHuman())); - } else if (account.isRobot()) { - builder.setAccountType(AccountDataType.ROBOT_ACCOUNT); - builder.setRobotAccountData(serialize(account.asRobot())); - } - return builder.build(); - } - - private static ProtoHumanAccountData serialize(HumanAccountData account) { - Preconditions.checkNotNull(account, "account is null"); - ProtoHumanAccountData.Builder builder = ProtoHumanAccountData.newBuilder(); - if (account.getPasswordDigest() != null) { - builder.setPasswordDigest(serialize(account.getPasswordDigest())); - } - return builder.build(); - } - - private static ProtoPasswordDigest serialize(PasswordDigest digest) { - Preconditions.checkNotNull(digest, "digest is null"); - return ProtoPasswordDigest.newBuilder() - .setSalt(ByteString.copyFrom(digest.getSalt())) - .setDigest(ByteString.copyFrom(digest.getDigest())) - .build(); - } - - private static ProtoRobotAccountData serialize(RobotAccountData account) { - Preconditions.checkNotNull(account, "account is null"); - ProtoRobotAccountData.Builder builder = ProtoRobotAccountData.newBuilder(); - builder.setUrl(account.getUrl()); - builder.setConsumerSecret(account.getConsumerSecret()); - builder.setIsVerified(account.isVerified()); - if (account.getCapabilities() != null) { - builder.setRobotCapabilities(serialize(account.getCapabilities())); - } - return builder.build(); - } - - private static ProtoRobotCapabilities serialize(RobotCapabilities capabilities) { - ProtoRobotCapabilities.Builder builder = ProtoRobotCapabilities.newBuilder(); - builder.setProtocolVersion(capabilities.getProtocolVersion().getVersionString()); - builder.setCapabilitiesHash(capabilities.getCapabilitiesHash()); - if (capabilities.getCapabilitiesMap() != null) { - for (Capability capability: capabilities.getCapabilitiesMap().values()) { - builder.addCapability(serialize(capability)); - } - } - return builder.build(); - } - - private static ProtoRobotCapability serialize(Capability capability) { - ProtoRobotCapability.Builder builder = ProtoRobotCapability.newBuilder(); - builder.setEventType(capability.getEventType().name()); - builder.setFilter(capability.getFilter()); - for (Context context: capability.getContexts()) { - builder.addContext(context.name()); - } - return builder.build(); - } - - /** - * Deserialize {@link ProtoAccountData} into {@link AccountData}. - */ - public static AccountData deserialize(ProtoAccountData data) { - switch (data.getAccountType()) { - case HUMAN_ACCOUNT: - Preconditions.checkArgument(data.hasHumanAccountData(), - "ProtoAccountData is missing the human_account_data field"); - return deserialize(data.getAccountId(), data.getHumanAccountData()); - case ROBOT_ACCOUNT: - Preconditions.checkArgument(data.hasRobotAccountData(), - "ProtoAccountData is missing the robot_account_data field"); - return deserialize(data.getAccountId(), data.getRobotAccountData()); - default: - throw new IllegalArgumentException( - "ProtoAccountData contains neither HumanAccountData nor RobotAccountData."); - } - } - - private static HumanAccountData deserialize(String account_id, ProtoHumanAccountData data) { - ParticipantId id = ParticipantId.ofUnsafe(account_id); - if (data.hasPasswordDigest()) { - return new HumanAccountDataImpl(id, deserialize(data.getPasswordDigest())); - } else { - return new HumanAccountDataImpl(id); - } - } - - private static PasswordDigest deserialize(ProtoPasswordDigest data) { - return PasswordDigest.from(data.getSalt().toByteArray(), data.getDigest().toByteArray()); - } - - private static RobotAccountData deserialize(String account_id, ProtoRobotAccountData data) { - ParticipantId id = ParticipantId.ofUnsafe(account_id); - RobotCapabilities capabilities = null; - if (data.hasRobotCapabilities()) { - capabilities = deserialize(data.getRobotCapabilities()); - } - return new RobotAccountDataImpl(id, data.getUrl(), data.getConsumerSecret(), - capabilities, data.getIsVerified()); - } - - private static RobotCapabilities deserialize(ProtoRobotCapabilities data) { - Map<EventType, Capability> capabilities = Maps.newHashMap(); - for (ProtoRobotCapability capabilityData: data.getCapabilityList()) { - Capability capability = deserialize(capabilityData); - capabilities.put(capability.getEventType(), capability); - } - return new RobotCapabilities(capabilities, data.getCapabilitiesHash(), - ProtocolVersion.fromVersionString(data.getProtocolVersion())); - } - - private static Capability deserialize(ProtoRobotCapability data) { - List<Context> contexts = Lists.newArrayList(); - for (String str: data.getContextList()) { - contexts.add(Context.valueOf(str)); - } - return new Capability(EventType.valueOf(data.getEventType()), contexts, data.getFilter()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoDeltaStoreDataSerializer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoDeltaStoreDataSerializer.java b/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoDeltaStoreDataSerializer.java deleted file mode 100644 index 549dc02..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/persistence/protos/ProtoDeltaStoreDataSerializer.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.persistence.protos; - -import com.google.common.collect.ImmutableList; - -import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer; -import org.waveprotocol.box.server.persistence.protos.ProtoDeltaStoreData.ProtoTransformedWaveletDelta; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.operation.wave.WaveletOperation; -import org.waveprotocol.wave.model.operation.wave.WaveletOperationContext; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * This class is used to serialize and deserialize {@link TransformedWavelwetDelta} - * and {@link ProtoTransformedWavelwetDelta} - * - * @author [email protected] (Tad Glines) - */ -public class ProtoDeltaStoreDataSerializer { - - /** - * Serialize a {@link TransformedWaveletDelta} into a {@link ProtoTransformedWaveletDelta} - */ - public static ProtoTransformedWaveletDelta serialize(TransformedWaveletDelta delta) { - ProtoTransformedWaveletDelta.Builder builder = ProtoTransformedWaveletDelta.newBuilder(); - builder.setAuthor(delta.getAuthor().getAddress()); - builder.setResultingVersion( - CoreWaveletOperationSerializer.serialize(delta.getResultingVersion())); - builder.setApplicationTimestamp(delta.getApplicationTimestamp()); - for (WaveletOperation op : delta) { - builder.addOperation(CoreWaveletOperationSerializer.serialize(op)); - } - return builder.build(); - } - - /** - * Deserialize a {@link ProtoTransformedWaveletDelta} into a {@link TransformedWaveletDelta} - */ - public static TransformedWaveletDelta deserialize(ProtoTransformedWaveletDelta delta) { - long applicationTimestamp = delta.getApplicationTimestamp(); - HashedVersion resultingVersion = - CoreWaveletOperationSerializer.deserialize(delta.getResultingVersion()); - ParticipantId author = ParticipantId.ofUnsafe(delta.getAuthor()); - ImmutableList.Builder<WaveletOperation> operations = ImmutableList.builder(); - int numOperations = delta.getOperationCount(); - for (int i = 0; i < numOperations; i++) { - WaveletOperationContext context; - if (i == numOperations - 1) { - context = new WaveletOperationContext(author, applicationTimestamp, 1, resultingVersion); - } else { - context = new WaveletOperationContext(author, applicationTimestamp, 1); - } - operations.add(CoreWaveletOperationSerializer.deserialize(delta.getOperation(i), context)); - } - return new TransformedWaveletDelta(author, resultingVersion, applicationTimestamp, operations.build()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/AbstractOperationServiceRegistry.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/AbstractOperationServiceRegistry.java b/wave/src/main/java/org/waveprotocol/box/server/robots/AbstractOperationServiceRegistry.java deleted file mode 100644 index 11e2e7f..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/AbstractOperationServiceRegistry.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import com.google.common.collect.Maps; -import com.google.wave.api.InvalidRequestException; -import com.google.wave.api.OperationType; - -import org.waveprotocol.box.server.robots.operations.OperationService; -import org.waveprotocol.wave.util.logging.Log; - -import java.util.Map; - -/** - * Abstract class for registering and accessing {@link OperationService} to - * execute operations for use in the Robot APIs. Note that this class is not - * thread safe. - * - * Implementations of this class are expected to define the way and moment when - * operations are registered. - * - * @author [email protected] (Lennard de Rijk) - */ -public abstract class AbstractOperationServiceRegistry implements OperationServiceRegistry { - - private static Log LOG = Log.get(AbstractOperationServiceRegistry.class); - - private Map<OperationType, OperationService> operationMap = Maps.newHashMap(); - - public AbstractOperationServiceRegistry() { - } - - @Override - public final OperationService getServiceFor(OperationType opType) throws InvalidRequestException { - OperationService service = operationMap.get(opType); - if (service == null) { - throw new InvalidRequestException("No OperationService found for " + opType); - } - return service; - } - - /** - * Registers the {@link OperationService} for the given {@link OperationType}. - * - * @param operation the type of the operation to register for - * @param service the {@link OperationService} to be registered - */ - protected final void register(OperationType operation, OperationService service) { - // Do a put first so we can make it use a concurrent map if needed. - OperationService oldValue = operationMap.put(operation, service); - if (oldValue != null) { - LOG.warning("The OperationService for " + operation.name() + " was overwritten"); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContext.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContext.java b/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContext.java deleted file mode 100644 index 155f0e4..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContext.java +++ /dev/null @@ -1,224 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import com.google.common.collect.ImmutableSet; -import com.google.wave.api.InvalidRequestException; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.OperationRequest; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.event.Event; - -import org.waveprotocol.box.server.robots.util.ConversationUtil; -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ObservableConversationView; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.opbased.OpBasedWavelet; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.box.server.frontend.CommittedWaveletSnapshot; -import org.waveprotocol.wave.model.id.WaveletName; -import org.waveprotocol.box.common.Receiver; -import org.waveprotocol.wave.model.version.HashedVersion; - -import java.util.Map; - -/** - * Context for performing robot operations. - * - * <p> - * {@link OperationContext} throws {@link InvalidRequestException} because it is - * expected to be used together with an {@link OperationRequest}. - * - * @author [email protected] (Lennard de Rijk) - */ -public interface OperationContext { - - /** Marks temporary wave and blip ID's since V2 */ - final String TEMP_ID_MARKER = "TBD_"; - - /** - * @return true iff this context is bound to a wavelet. - */ - boolean isBound(); - - /** - * @param operationId the id of the robot operation. - * @return True iff a response has been set for the given id. - */ - boolean hasResponse(String operationId); - - /** - * Constructs a response with the given data in its payload field. - * - * @param data the data to be put in the repsonse. - */ - void constructResponse(OperationRequest operation, Map<ParamsProperty, Object> data); - - /** - * Constructs and stores a response signifying an error to be put in the - * context. - * - * @param errorMessage the error message to be put in the response. - */ - void constructErrorResponse(OperationRequest operation, String errorMessage); - - /** - * Processes the event and sets the proper response. - * - * @param event the event to process. - * @throws InvalidRequestException If the event could not be properly - * processed. - */ - void processEvent(OperationRequest operation, Event event) throws InvalidRequestException; - - /** - * Stores a reference from a temporary wavelet id to a real wavelet id. If the - * given id is not a temporary id no reference will be stored. - * - * @param waveId the wave id. - * @param waveletId the wavelet id. - * @param newWavelet the new wavelet to remember. - */ - void putWavelet(WaveId waveId, WaveletId waveletId, RobotWaveletData newWavelet); - - /** - * Opens a wavelet for the given wave id and wavelet id. Note: Usually if the - * wavelet for specified wavelet id doesn't exist - the method returns - * null. However, for user data wavelets the method will create a new empty one - * and return it. - * - * @param waveId the wave id of the wavelet to open. - * @param waveletId the wavelet id of the wavelet to open. - * @param participant the id of the participant that wants to open the - * wavelet. - * @throws InvalidRequestException if the wavelet can not be opened. - */ - OpBasedWavelet openWavelet(WaveId waveId, WaveletId waveletId, ParticipantId participant) - throws InvalidRequestException; - - /** - * Opens the wavelet specified in the given operation. Note: Usually if the - * wavelet for specified wavelet id doesn't exist - the method returns - * null. However, for user data wavelets the method will create a new empty one - * and return it. - * - * @param operation the operation specifying which wavelet to open. - * @param participant the id of the participant that wants to open the - * wavelet. - * @throws InvalidRequestException if the wavelet can not be opened or the - * operation does not define the wave and wavelet id. - */ - OpBasedWavelet openWavelet(OperationRequest operation, ParticipantId participant) - throws InvalidRequestException; - - /** - * Gets the conversation for of wavelet for the given wave id and wavelet id. - * Tries to retrieve and open the wavelet if that has not already been done. - * - * @param waveId the wave id of the wavelet. - * @param waveletId the wavelet id of. - * @param participant the id of the participant that wants to operation on the - * conversation. - * @throws InvalidRequestException if the wavelet can not be opened. - */ - ObservableConversationView openConversation( - WaveId waveId, WaveletId waveletId, ParticipantId participant) throws InvalidRequestException; - - /** - * Gets the conversation for of wavelet specified in the operation. Tries to - * retrieve and open the wavelet if that has not already been done. - * - * @param operation the operation specifying which wavelet to get the - * conversation for. - * @param participant the id of the participant that wants to operation on the - * conversation. - * @throws InvalidRequestException if the wavelet can not be opened or the - * operation does not define the wave and wavelet id. - */ - ObservableConversationView openConversation(OperationRequest operation, ParticipantId participant) - throws InvalidRequestException; - - /** - * Stores a reference from a temporary blip id to a real blip id. If the given - * id is not a temporary id it will be ignored. - * - * @param blipId the temporary blip id. - * @param newBlip the blip that this id should reference. - */ - void putBlip(String blipId, ConversationBlip newBlip); - - /** - * Retrieve a blip with the given, possible temporary id, from the - * conversation. - * - * @param conversation the conversation the blip belongs to. - * @param blipId the id of the blip, may be be a temporary id. - * @throws InvalidRequestException if the blip could not be retrieved or has - * been deleted. - */ - ConversationBlip getBlip(Conversation conversation, String blipId) throws InvalidRequestException; - - /** - * @return the converter to convert to API objects - */ - EventDataConverter getConverter(); - - /** - * Returns {@link ConversationUtil} which is used to generate conversations - * and ids. - */ - ConversationUtil getConversationUtil(); - - /** - * Gets the list of wavelet Ids that are visible to the user. - * - * @param operation the operation specifying wave. - * @param participant the user. - * @return set of wavelet Ids, visible to the user. - */ - ImmutableSet<WaveletId> getVisibleWaveletIds(OperationRequest operation, ParticipantId participant) - throws InvalidRequestException; - - /** - * Takes snapshot of a wavelet, checking access for the given participant. - * - * @param waveletName the wavelet name of the wavelet to get. - * @param participant the user. - * @return snapshot on success, null on failure - */ - CommittedWaveletSnapshot getWaveletSnapshot(WaveletName waveletName, ParticipantId participant) - throws InvalidRequestException; - - /** - * Takes deltas history of a wavelet, checking access for the given participant. - * - * @param waveletName the wavelet name of the wavelet to get. - * @param participant the user. - * @param fromVersion start version (inclusive), minimum 0. - * @param toVersion start version (exclusive). - * @param receiver the transformed deltas receiver. - */ - void getDeltas(WaveletName waveletName, ParticipantId participant, - HashedVersion fromVersion, HashedVersion toVersion, Receiver<TransformedWaveletDelta> receiver) - throws InvalidRequestException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContextImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContextImpl.java b/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContextImpl.java deleted file mode 100644 index 03874ea..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationContextImpl.java +++ /dev/null @@ -1,406 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import static org.waveprotocol.box.server.robots.util.RobotsUtil.createEmptyRobotWavelet; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.wave.api.ApiIdSerializer; -import com.google.wave.api.InvalidRequestException; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.JsonRpcResponse; -import com.google.wave.api.OperationRequest; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.event.Event; -import com.google.wave.api.event.EventSerializationException; -import com.google.wave.api.event.EventSerializer; -import com.google.wave.api.event.EventType; -import com.google.wave.api.event.OperationErrorEvent; - -import org.waveprotocol.box.common.Receiver; -import org.waveprotocol.box.server.frontend.CommittedWaveletSnapshot; -import org.waveprotocol.box.server.robots.util.ConversationUtil; -import org.waveprotocol.box.server.robots.util.OperationUtil; -import org.waveprotocol.box.server.waveserver.WaveServerException; -import org.waveprotocol.box.server.waveserver.WaveletProvider; -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ObservableConversationView; -import org.waveprotocol.wave.model.id.IdUtil; -import org.waveprotocol.wave.model.id.InvalidIdException; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.id.WaveletName; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.schema.SchemaCollection; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.data.ObservableWaveletData; -import org.waveprotocol.wave.model.wave.data.impl.ObservablePluggableMutableDocument; -import org.waveprotocol.wave.model.wave.data.impl.WaveletDataImpl; -import org.waveprotocol.wave.model.wave.opbased.OpBasedWavelet; -import org.waveprotocol.wave.util.logging.Log; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Class which provides context for robot operations and gives access to the - * results. - * - * @author [email protected] (Lennard de Rijk) - */ -public class OperationContextImpl implements OperationContext, OperationResults { - - private static final Log LOG = Log.get(OperationContextImpl.class); - - private static final ObservableWaveletData.Factory<? extends ObservableWaveletData> FACTORY = - WaveletDataImpl.Factory.create( - ObservablePluggableMutableDocument.createFactory(SchemaCollection.empty())); - - /** - * Maps operation ID's to responses. - */ - private final Map<String, JsonRpcResponse> responses = Maps.newHashMap(); - - /** - * {@link WaveletProvider} that gives us access to wavelets. - */ - private final WaveletProvider waveletProvider; - - /** - * {@link EventDataConverter} that can convert to - * {@link com.google.wave.api.impl.WaveletData} and such. - */ - private final EventDataConverter converter; - - /** - * The wavelet to which this context is bound, null if unbound. - */ - private final RobotWaveletData boundWavelet; - - /** - * The wavelets that have been opened in the lifespan of this context. - */ - private final Map<WaveletName, RobotWaveletData> openedWavelets = Maps.newHashMap(); - - /** Stores temporary blip ids -> real blip ids */ - private final Map<String, String> tempBlipIdMap = Maps.newHashMap(); - /** Stores temporary wavelet names -> real wavelet names */ - private final Map<WaveletName, WaveletName> tempWaveletNameMap = Maps.newHashMap(); - /** Caches {@link ObservableConversationView}s */ - private final Map<WaveletName, Map<ParticipantId, ObservableConversationView>> - openedConversations; - - /** Used to create conversations. */ - private final ConversationUtil conversationUtil; - - /** - * Constructs an operation context not bound to any wavelet. - * - * @param waveletProvider the waveletprovider to use for querying wavelet. - * @param converter {@link EventDataConverter} for converting from server side - * objects. - * @param conversationUtil used to create conversations. - */ - public OperationContextImpl(WaveletProvider waveletProvider, EventDataConverter converter, - ConversationUtil conversationUtil) { - this(waveletProvider, converter, conversationUtil, null); - } - - /** - * Constructs a bound operation context. The bound wavelet is added to the - * list of open wavelets. - * - * @param waveletProvider the waveletprovider to use for querying wavelet. - * @param converter {@link EventDataConverter} for converting from server side - * objects. - * @param boundWavelet the wavelet to bind this context to, null for an - * unbound context. - * @param conversationUtil used to create conversations. - */ - public OperationContextImpl(WaveletProvider waveletProvider, EventDataConverter converter, - ConversationUtil conversationUtil, RobotWaveletData boundWavelet) { - this.waveletProvider = waveletProvider; - this.converter = converter; - this.conversationUtil = conversationUtil; - this.boundWavelet = boundWavelet; - this.openedConversations = Maps.newHashMap(); - - if (boundWavelet != null) { - openedWavelets.put(boundWavelet.getWaveletName(), boundWavelet); - } - } - - // OperationContext implementation begins here - - @Override - public EventDataConverter getConverter() { - return converter; - } - - @Override - public boolean isBound() { - return boundWavelet != null; - } - - @Override - public Map<WaveletName, RobotWaveletData> getOpenWavelets() { - return Collections.unmodifiableMap(openedWavelets); - } - - @Override - public void constructResponse(OperationRequest operation, Map<ParamsProperty, Object> data) { - setResponse(operation.getId(), JsonRpcResponse.result(operation.getId(), data)); - } - - @Override - public void constructErrorResponse(OperationRequest operation, String errorMessage) { - setResponse(operation.getId(), JsonRpcResponse.error(operation.getId(), errorMessage)); - } - - @Override - public void processEvent(OperationRequest operation, Event event) throws InvalidRequestException { - // Create JSON-RPC error response. - if (event.getType() == EventType.OPERATION_ERROR) { - constructErrorResponse(operation, OperationErrorEvent.as(event).getMessage()); - return; - } - // Create JSON-RPC success response. - try { - constructResponse(operation, EventSerializer.extractPropertiesToParamsPropertyMap(event)); - } catch (EventSerializationException e) { - LOG.severe("Internal Error occurred, when serializing events", e); - throw new InvalidRequestException("Unable to serialize events", operation); - } - } - - @Override - public void putWavelet(WaveId waveId, WaveletId waveletId, RobotWaveletData newWavelet) { - WaveletName waveletName = newWavelet.getWaveletName(); - Preconditions.checkArgument(!openedWavelets.containsKey(waveletName), - "Not allowed to put an already open wavelet in as a new wavelet"); - - // New wavelets are indicated by the temporary marker in their waveId. - if (waveId.getId().startsWith(TEMP_ID_MARKER)) { - tempWaveletNameMap.put(WaveletName.of(waveId, waveletId), waveletName); - } - openedWavelets.put(waveletName, newWavelet); - } - - @Override - public OpBasedWavelet openWavelet(WaveId waveId, WaveletId waveletId, ParticipantId participant) - throws InvalidRequestException { - WaveletName waveletName; - if (waveId.getId().startsWith(TEMP_ID_MARKER)) { - WaveletName tempWaveletName = WaveletName.of(waveId, waveletId); - waveletName = tempWaveletNameMap.get(tempWaveletName); - } else { - waveletName = WaveletName.of(waveId, waveletId); - } - - RobotWaveletData wavelet = openedWavelets.get(waveletName); - if (wavelet == null) { - // Open a wavelet from the server - CommittedWaveletSnapshot snapshot = getWaveletSnapshot(waveletName, participant); - if (snapshot == null) { - if (waveletName.waveletId.equals(IdUtil.buildUserDataWaveletId(participant))) { - // Usually the user data is created by the web client whenever user - // opens a wavelet for the first time. However, if the wavelet is - // fetched for the first time with Robot/Data API - user data should be - // created here. - wavelet = createEmptyRobotWavelet(participant, waveletName); - } else { - throw new InvalidRequestException("Wavelet " + waveletName + " couldn't be retrieved"); - } - - } else { - ObservableWaveletData obsWavelet = FACTORY.create(snapshot.snapshot); - wavelet = new RobotWaveletData(obsWavelet, snapshot.committedVersion); - } - openedWavelets.put(waveletName, wavelet); - } - return wavelet.getOpBasedWavelet(participant); - } - - @Override - public OpBasedWavelet openWavelet(OperationRequest operation, ParticipantId participant) - throws InvalidRequestException { - try { - WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( - OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); - WaveletId waveletId = ApiIdSerializer.instance().deserialiseWaveletId( - OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); - return openWavelet(waveId, waveletId, participant); - } catch (InvalidIdException e) { - throw new InvalidRequestException("Invalid id", operation, e); - } - } - - @Override - public ObservableConversationView openConversation(WaveId waveId, WaveletId waveletId, - ParticipantId participant) throws InvalidRequestException { - WaveletName waveletName = WaveletName.of(waveId, waveletId); - - if (!openedConversations.containsKey(waveletName)) { - openedConversations.put( - waveletName, Maps.<ParticipantId, ObservableConversationView> newHashMap()); - } - - Map<ParticipantId, ObservableConversationView> conversations = - openedConversations.get(waveletName); - - if (!conversations.containsKey(participant)) { - OpBasedWavelet wavelet = openWavelet(waveId, waveletId, participant); - conversations.put(participant, conversationUtil.buildConversation(wavelet)); - } - return conversations.get(participant); - } - - @Override - public ObservableConversationView openConversation( - OperationRequest operation, ParticipantId participant) throws InvalidRequestException { - try { - WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( - OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); - WaveletId waveletId = ApiIdSerializer.instance().deserialiseWaveletId( - OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); - return openConversation(waveId, waveletId, participant); - } catch (InvalidIdException e) { - throw new InvalidRequestException("Invalid id", operation, e); - } - } - - // OperationResults implementation begins here - - @Override - public void putBlip(String blipId, ConversationBlip newBlip) { - if (blipId.startsWith(TEMP_ID_MARKER)) { - tempBlipIdMap.put(blipId, newBlip.getId()); - } - } - - @Override - public ConversationBlip getBlip(Conversation conversation, String blipId) - throws InvalidRequestException { - // We might need to look up the blip id for new blips. - String actualBlipId = blipId.startsWith(TEMP_ID_MARKER) ? tempBlipIdMap.get(blipId) : blipId; - - ConversationBlip blip = conversation.getBlip(actualBlipId); - if (blip == null) { - throw new InvalidRequestException( - "Blip with id " + blipId + " does not exist or has been deleted"); - } - - return blip; - } - - // OperationResults implementation begins here - - @Override - public ConversationUtil getConversationUtil() { - return conversationUtil; - } - - @Override - public Map<String, JsonRpcResponse> getResponses() { - return Collections.unmodifiableMap(responses); - } - - @Override - public JsonRpcResponse getResponse(String operationId) { - return responses.get(operationId); - } - - @Override - public boolean hasResponse(String operationId) { - return responses.containsKey(operationId); - } - - @Override - public ImmutableSet<WaveletId> getVisibleWaveletIds(OperationRequest operation, ParticipantId participant) - throws InvalidRequestException { - Set<WaveletId> waveletIds = new HashSet<WaveletId>(); - try { - WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( - OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); - ImmutableSet<WaveletId> ids = waveletProvider.getWaveletIds(waveId); - for (WaveletId waveletId: ids) { - WaveletName waveletName = WaveletName.of(waveId, waveletId); - if (waveletProvider.checkAccessPermission(waveletName, participant)) { - waveletIds.add(waveletId); - } - } - } catch (InvalidIdException ex) { - throw new InvalidRequestException("Invalid id", operation, ex); - } catch (WaveServerException e) { - LOG.severe("Error of access to wave", e); - } - return ImmutableSet.copyOf(waveletIds); - } - - @Override - public CommittedWaveletSnapshot getWaveletSnapshot(WaveletName waveletName, ParticipantId participant) - throws InvalidRequestException { - try { - if (!waveletProvider.checkAccessPermission(waveletName, participant)) { - throw new InvalidRequestException("Access rejected"); - } - return waveletProvider.getSnapshot(waveletName); - } catch (WaveServerException ex) { - LOG.severe("Error of access to wavelet " + waveletName, ex); - return null; - } - } - - @Override - public void getDeltas(WaveletName waveletName, ParticipantId participant, - HashedVersion fromVersion, HashedVersion toVersion, Receiver<TransformedWaveletDelta> receiver) - throws InvalidRequestException { - try { - if (!waveletProvider.checkAccessPermission(waveletName, participant)) { - throw new InvalidRequestException("Access rejected"); - } - Preconditions.checkState(fromVersion.compareTo(toVersion) <= 0); - if (fromVersion.equals(toVersion)) { - return; - } - waveletProvider.getHistory(waveletName, fromVersion, toVersion, receiver); - } catch (WaveServerException ex) { - LOG.severe("Error of access to wavelet " + waveletName, ex); - } - } - - /** - * Stores a response in this context. - * - * @param operationId the id of the robot operation. - * @param response the response to store. - */ - private void setResponse(String operationId, JsonRpcResponse response) { - Preconditions.checkState( - !responses.containsKey(operationId), "Overwriting an existing response"); - responses.put(operationId, response); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/OperationResults.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationResults.java b/wave/src/main/java/org/waveprotocol/box/server/robots/OperationResults.java deleted file mode 100644 index 874e5fe..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationResults.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import com.google.wave.api.JsonRpcResponse; - -import org.waveprotocol.wave.model.id.WaveletName; - -import java.util.Map; - -/** - * Interface for accessing robot operation results. - * - * @author [email protected] (Lennard de Rijk) - */ -public interface OperationResults { - - /** - * Returns an unmodifiable view of all wavelets that have been opened when - * performing robot operations. - */ - Map<WaveletName, RobotWaveletData> getOpenWavelets(); - - /** - * Returns an unmodifiable view of all responses that have been generated by - * performing robot operations. - */ - Map<String, JsonRpcResponse> getResponses(); - - /** - * Returns a response for a specific robot operation. - * - * @param operationId the id of the robot operation to get the response for. - * @return returns a {@link JsonRpcResponse} if set else null. - */ - JsonRpcResponse getResponse(String operationId); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/OperationServiceRegistry.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationServiceRegistry.java b/wave/src/main/java/org/waveprotocol/box/server/robots/OperationServiceRegistry.java deleted file mode 100644 index 9ddac1b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/OperationServiceRegistry.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import com.google.wave.api.InvalidRequestException; -import com.google.wave.api.OperationType; - -import org.waveprotocol.box.server.robots.operations.OperationService; - -/** - * Registry for accessing an {@link OperationService} to execute operations in - * the Robot APIs. - * - * @author [email protected] (Lennard de Rijk) - */ -public interface OperationServiceRegistry { - - /** - * Retrieves the {@link OperationService} for the given {@link OperationType}. - * - * @param opType the type of operation to retrieve the service for - * @return {@link OperationService} registered for the given - * {@link OperationType} - * @throws InvalidRequestException if no {@link OperationService} could be - * found. - */ - OperationService getServiceFor(OperationType opType) throws InvalidRequestException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/robots/ProfileFetcherModule.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/robots/ProfileFetcherModule.java b/wave/src/main/java/org/waveprotocol/box/server/robots/ProfileFetcherModule.java deleted file mode 100644 index 7374bfc..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/robots/ProfileFetcherModule.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.waveprotocol.box.server.robots; - -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.typesafe.config.Config; -import org.waveprotocol.box.server.robots.operations.FetchProfilesService.ProfilesFetcher; -import org.waveprotocol.box.server.robots.operations.GravatarProfilesFetcher; -import org.waveprotocol.box.server.robots.operations.InitialsProfilesFetcher; - -/** - * Profile Fetcher Module. - * - * @author [email protected] (Vicente J. Ruiz Jurado) - */ -public class ProfileFetcherModule extends AbstractModule { - - - private String profileFetcherType; - - @Inject - public ProfileFetcherModule(Config config) { - this.profileFetcherType = config.getString("core.profile_fetcher_type"); - } - - @Override - protected void configure() { - if ("gravatar".equals(profileFetcherType)) { - bind(ProfilesFetcher.class).to(GravatarProfilesFetcher.class).in(Singleton.class); - } else if ("initials".equals(profileFetcherType)) { - bind(ProfilesFetcher.class).to(InitialsProfilesFetcher.class).in(Singleton.class); - } else { - throw new RuntimeException("Unknown profile fetcher type: " + profileFetcherType); - } - } -}
