http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/Snippets.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/Snippets.java b/src/org/waveprotocol/box/common/Snippets.java deleted file mode 100644 index 52a9323..0000000 --- a/src/org/waveprotocol/box/common/Snippets.java +++ /dev/null @@ -1,226 +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.common; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -import org.waveprotocol.wave.model.document.operation.AnnotationBoundaryMap; -import org.waveprotocol.wave.model.document.operation.Attributes; -import org.waveprotocol.wave.model.document.operation.AttributesUpdate; -import org.waveprotocol.wave.model.document.operation.DocInitializationCursor; -import org.waveprotocol.wave.model.document.operation.DocOp; -import org.waveprotocol.wave.model.document.operation.DocOpCursor; -import org.waveprotocol.wave.model.document.operation.impl.InitializationCursorAdapter; -import org.waveprotocol.wave.model.wave.data.ReadableBlipData; -import org.waveprotocol.wave.model.wave.data.ReadableWaveletData; -import org.waveprotocol.wave.model.wave.data.WaveletData; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -/** - * Utility methods for rendering snippets. - * - * @author [email protected] (Alex North) - */ -public final class Snippets { - - private final static Function<StringBuilder, Void> DEFAULT_LINE_MODIFIER = - new Function<StringBuilder, Void>() { - - @Override - public Void apply(StringBuilder resultBuilder) { - resultBuilder.append(" "); - return null; - } - }; - public static final int DIGEST_SNIPPET_LENGTH = 140; - - /** - * Concatenates all of the text for the given documents in - * {@link WaveletData}. - * - * @param wavelet the wavelet for which to concatenate the documents. - * @return A String containing the characters from all documents. - */ - public static String collateTextForWavelet(ReadableWaveletData wavelet) { - List<ReadableBlipData> documents = new ArrayList<ReadableBlipData>(); - for (String documentId : wavelet.getDocumentIds()) { - documents.add(wavelet.getDocument(documentId)); - } - return collateTextForDocuments(documents); - } - - /** - * Concatenates all of the text of the specified blips into a single String. - * - * @param documents the documents to concatenate. - * @return A String containing the characters from all documents. - */ - public static String collateTextForDocuments(Iterable<? extends ReadableBlipData> documents) { - ArrayList<DocOp> docOps = new ArrayList<DocOp>(); - for (ReadableBlipData blipData : documents) { - docOps.add(blipData.getContent().asOperation()); - } - return collateTextForOps(docOps); - } - - /** - * Concatenates all of the text of the specified docops into a single String. - * - * @param documentops the document operations to concatenate. - * @param func the function that will be applied on result when - * DocumentConstants.LINE event is be encountered during parsing. - * @return A String containing the characters from the operations. - */ - public static String collateTextForOps(Iterable<? extends DocOp> documentops, - final Function<StringBuilder, Void> func) { - final StringBuilder resultBuilder = new StringBuilder(); - for (DocOp docOp : documentops) { - docOp.apply(InitializationCursorAdapter.adapt(new DocOpCursor() { - @Override - public void characters(String s) { - resultBuilder.append(s); - } - - @Override - public void annotationBoundary(AnnotationBoundaryMap map) { - } - - @Override - public void elementStart(String type, Attributes attrs) { - if (type.equals(DocumentConstants.LINE)) { - func.apply(resultBuilder); - } - } - - @Override - public void elementEnd() { - } - - @Override - public void retain(int itemCount) { - } - - @Override - public void deleteCharacters(String chars) { - } - - @Override - public void deleteElementStart(String type, Attributes attrs) { - } - - @Override - public void deleteElementEnd() { - } - - @Override - public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) { - } - - @Override - public void updateAttributes(AttributesUpdate attrUpdate) { - } - })); - } - return resultBuilder.toString().trim(); - } - - /** - * Concatenates all of the text of the specified docops into a single String. - * - * @param documentops the document operations to concatenate. - * @return A String containing the characters from the operations. - */ - public static String collateTextForOps(Iterable<? extends DocOp> documentops) { - return collateTextForOps(documentops, DEFAULT_LINE_MODIFIER); - } - - /** - * Returns a snippet or null. - */ - public static String renderSnippet(final ReadableWaveletData wavelet, - final int maxSnippetLength) { - final StringBuilder sb = new StringBuilder(); - Set<String> docsIds = wavelet.getDocumentIds(); - long newestLmt = -1; - ReadableBlipData newestBlip = null; - for (String docId : docsIds) { - ReadableBlipData blip = wavelet.getDocument(docId); - long currentLmt = blip.getLastModifiedTime(); - if (currentLmt > newestLmt) { - newestLmt = currentLmt; - newestBlip = blip; - } - } - if (newestBlip == null) { - // Render whatever data we have and hope its good enough - sb.append(collateTextForWavelet(wavelet)); - } else { - DocOp docOp = newestBlip.getContent().asOperation(); - sb.append(collateTextForOps(Lists.newArrayList(docOp))); - sb.append(" "); - docOp.apply(InitializationCursorAdapter.adapt(new DocInitializationCursor() { - @Override - public void annotationBoundary(AnnotationBoundaryMap map) { - } - - @Override - public void characters(String chars) { - // No chars in the conversation manifest - } - - @Override - public void elementEnd() { - } - - @Override - public void elementStart(String type, Attributes attrs) { - if (sb.length() >= maxSnippetLength) { - return; - } - - if (DocumentConstants.BLIP.equals(type)) { - String blipId = attrs.get(DocumentConstants.BLIP_ID); - if (blipId != null) { - ReadableBlipData document = wavelet.getDocument(blipId); - if (document == null) { - // We see this when a blip has been deleted - return; - } - sb.append(collateTextForDocuments(Arrays.asList(document))); - sb.append(" "); - } - } - } - })); - } - if (sb.length() > maxSnippetLength) { - return sb.substring(0, maxSnippetLength); - } - return sb.toString(); - } - - private Snippets() { - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/comms/WaveClientRpc.gwt.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/comms/WaveClientRpc.gwt.xml b/src/org/waveprotocol/box/common/comms/WaveClientRpc.gwt.xml deleted file mode 100644 index 7393ff6..0000000 --- a/src/org/waveprotocol/box/common/comms/WaveClientRpc.gwt.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version='1.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. - ---> - -<module> - <inherits name="org.waveprotocol.wave.federation.Federation"/> - <!-- DTO deps below. --> - <inherits name="org.waveprotocol.wave.communication.Communication"/> - <source path="" excludes="gson/** proto/**"/> -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/common/comms/waveclient-rpc.proto ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/common/comms/waveclient-rpc.proto b/src/org/waveprotocol/box/common/comms/waveclient-rpc.proto deleted file mode 100644 index 7b308a8..0000000 --- a/src/org/waveprotocol/box/common/comms/waveclient-rpc.proto +++ /dev/null @@ -1,199 +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. -// -// The wave view client-server protocol -// -// Author: [email protected] (Jochen Bekmann) -// Author: [email protected] (Alex North) - -syntax = "proto2"; - -import "org/waveprotocol/box/server/rpc/rpc.proto"; -import "org/waveprotocol/wave/federation/federation.protodevel"; - -package waveserver; - -option java_package = "org.waveprotocol.box.common.comms"; -option java_outer_classname = "WaveClientRpc"; -option java_generic_services = true; - -/** - * Provides streaming wave views. - * - * A client requests a possibly filtered view of wavelets in a wave. - * The response stream contains first a snapshot for each wavelet - * currently in view, and then deltas for those wavelets. The end of - * the initial set of snapshots is indicated by a "marker" message. - * New wavelets may come into view after the marker, resulting in - * another snapshot. - * - * The client may indicate that it already has a snapshot for some wavelets - * by providing one or more known versions and signatures. If one matches - * the server history the server will not send a snapshot but will instead - * begin the stream with an empty delta specifying the resynchronization - * version. - * - * TODO(anorth): - * - make the first response message a channel id only, then no more - * channel ids - */ -service ProtocolWaveClientRpc { - rpc Open (ProtocolOpenRequest) returns (ProtocolWaveletUpdate) { - option (rpc.is_streaming_rpc) = true; - }; - rpc Submit (ProtocolSubmitRequest) returns (ProtocolSubmitResponse); - rpc Authenticate (ProtocolAuthenticate) returns (ProtocolAuthenticationResult); -} - -// A workaround for clients which do not support sending cookies over a websocket -// connection. See: http://code.google.com/p/wave-protocol/issues/detail?id=119 -message ProtocolAuthenticate { - required string token = 1; -} - -// RPCs require a return type, although in this case no return data is desired. -// We don't want to return anything here because clients which implement -// websockets correctly (and thus don't use ProtocolAuthenticate) cannot -// recieve the authentication related information. -// If the client's authentication is not valid, the connection will be closed. -message ProtocolAuthenticationResult { -} - -/** - * A request to open a wave view. - */ -message ProtocolOpenRequest { - // User making the request. - // TODO(anorth): Remove this, replacing it with the implicit logged-in user. - required string participant_id = 1; - // Wave id to open. - required string wave_id = 2; - // Wavelet id prefixes by which to filter the view, empty means no filter. - repeated string wavelet_id_prefix = 3; - // Known wavelet versions for resynchronization. - repeated WaveletVersion known_wavelet = 4; -} - -// A pair of (wavelet id, wavelet version) -message WaveletVersion { - required string wavelet_id = 1; - required federation.ProtocolHashedVersion hashed_version = 2; -} - -// A document and associated metadata -message DocumentSnapshot { - required string document_id = 1; - // This is a document operation that takes the document from zero to its current state. - required federation.ProtocolDocumentOperation document_operation = 2; - - // ** Metadata - // The participant who submitted the first operation to the document - required string author = 3; - // All participants who have submitted operations to the document - repeated string contributor = 4; - // The wavelet version when the document was last modified - required int64 last_modified_version = 5; - required int64 last_modified_time = 6; -} - -// A wavelet and associated metadata. -message WaveletSnapshot { - required string wavelet_id = 1; - // The list of participants of this wavelet. - repeated string participant_id = 2; - // Snapshots of all the documents in the wavelet. - repeated DocumentSnapshot document = 3; - - // ** Metadata - // The current version of the wavelet - required federation.ProtocolHashedVersion version = 4; - // The participant that created the wavelet - required int64 last_modified_time = 5; - required string creator = 6; - required int64 creation_time = 7; -} - -// A snapshot of a user's view of a wave. -// Contains snapshots of all the wavelets visible to a user -message WaveViewSnapshot { - required string wave_id = 1; - repeated WaveletSnapshot wavelet = 2; -} - -/** - * Update message for a wave view. - * Contains either: - * - a channel id (only) - * - a marker (only) - * - a wavelet name, snapshot, version, and commit version - * - a wavelet name, deltas, version - * Must contain either one or more applied deltas or a commit notice. - * - * TODO(anorth): rename to reflect that this is a view update, not wavelet - */ -message ProtocolWaveletUpdate { - // Specifies the wavelet name in the URI netpath notation. - // Set only if there are deltas - // TODO(anorth) make optional for channel id, marker updates - required string wavelet_name = 1; - - // Zero or more deltas for this wavelet, streamed in order. - // If snapshot is set, there should be zero deltas. - // TODO(soren): consider using this in the snapshot case for uncommitted deltas. - repeated federation.ProtocolWaveletDelta applied_delta = 2; - - // Indicates that the host server has committed the wavelet to disk at the - // given version. Mandatory for snapshots. - optional federation.ProtocolHashedVersion commit_notice = 3; - - // Resulting version of the wavelet after all deltas have been applied - // May only be missing if there are no appliedDeltas - // If snapshot is set, this is the version number of the snapshot, and is - // mandatory. - optional federation.ProtocolHashedVersion resulting_version = 4; - - // An optional snapshot of the wavelet - optional WaveletSnapshot snapshot = 5; - - // View open marker, signifies all current snapshots have been sent. - optional bool marker = 6 [default=false]; - - // Channel id, set only in the first update to a client. - // The client includes it in submits. - optional string channel_id = 7; -} - -/** - * The client requests that the given delta be applied to the wavelet. - */ -message ProtocolSubmitRequest { - required string wavelet_name = 1; - required federation.ProtocolWaveletDelta delta = 2; - optional string channel_id = 3; -} - -/** - * The result of submitting the delta to the server. If an error occurs - * errorMessage will be present, otherwise hashedVersionAfterApplication will be - * present. operationsApplied will report the actual number of operations - * successfully applied to the wavelet by the server. - */ -message ProtocolSubmitResponse { - required int32 operations_applied = 1; - optional string error_message = 2; - optional federation.ProtocolHashedVersion hashed_version_after_application = 3; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/Console.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/Console.java b/src/org/waveprotocol/box/expimp/Console.java deleted file mode 100644 index 381a41b..0000000 --- a/src/org/waveprotocol/box/expimp/Console.java +++ /dev/null @@ -1,64 +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.expimp; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Input/output for Export/Import utilities. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class Console { - - private static final Logger log = Logger.getLogger("ExportImport"); - - public static void print(String line) { - System.out.print(line); - } - - public static void println(String line) { - System.out.println(line); - } - - public static void println() { - System.out.println(); - } - - public static void error(String error) { - System.err.println(); - System.err.println(error); - } - - public static void error(String error, Exception ex) { - log.log(Level.SEVERE, error, ex); - System.err.println(); - System.err.println(error); - System.err.println(ex.toString()); - } - - public static String readLine() throws IOException { - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - return in.readLine(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/DeltaParser.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/DeltaParser.java b/src/org/waveprotocol/box/expimp/DeltaParser.java deleted file mode 100644 index b9db5aa..0000000 --- a/src/org/waveprotocol/box/expimp/DeltaParser.java +++ /dev/null @@ -1,84 +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.expimp; - -import com.google.protobuf.InvalidProtocolBufferException; -import org.waveprotocol.wave.federation.Proto.ProtocolDocumentOperation.Component; -import org.waveprotocol.wave.federation.Proto.ProtocolDocumentOperation.Component.ElementStart; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument; -import org.waveprotocol.wave.media.model.AttachmentId; -import org.waveprotocol.wave.model.id.InvalidIdException; -import org.waveprotocol.wave.model.image.ImageConstants; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Raw deltas parser. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class DeltaParser { - - private DeltaParser() { - } - - public static List<ProtocolWaveletDelta> parseDeltas(List<byte[]> rawDeltas) - throws InvalidProtocolBufferException { - List<ProtocolWaveletDelta> deltas = new ArrayList<ProtocolWaveletDelta>(); - for (byte[] delta : rawDeltas) { - deltas.add(ProtocolWaveletDelta.parseFrom(delta)); - } - return deltas; - } - - /** - * Extract attachment ids from operations. - */ - public static Set<AttachmentId> getAttachemntIds(ProtocolWaveletDelta delta) { - Set<AttachmentId> ids = new HashSet<AttachmentId>(); - for (int i=0; i < delta.getOperationCount(); i++) { - ProtocolWaveletOperation op = delta.getOperation(i); - if (op.hasMutateDocument()) { - MutateDocument doc = op.getMutateDocument(); - for (int c = 0; c < doc.getDocumentOperation().getComponentCount(); c++) { - Component comp = doc.getDocumentOperation().getComponent(c); - ElementStart start = comp.getElementStart(); - if (ImageConstants.TAGNAME.equals(start.getType())) { - for (int a=0; a < start.getAttributeCount(); a++) { - Component.KeyValuePair attr = start.getAttribute(a); - if (ImageConstants.ATTACHMENT_ATTRIBUTE.equals(attr.getKey())) { - try { - ids.add(AttachmentId.deserialise(attr.getValue())); - } catch (InvalidIdException ex) { - Console.error("Invalid attachment Id " + attr.getValue(), ex); - } - } - } - } - } - } - } - return ids; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/DomainConverter.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/DomainConverter.java b/src/org/waveprotocol/box/expimp/DomainConverter.java deleted file mode 100644 index 76a6911..0000000 --- a/src/org/waveprotocol/box/expimp/DomainConverter.java +++ /dev/null @@ -1,150 +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.expimp; - -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta; -import org.waveprotocol.wave.model.wave.InvalidParticipantAddress; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation; -import org.waveprotocol.wave.model.id.IdUtil; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; - -import java.util.LinkedList; -import java.util.List; - -/** - * Converts domain names in exported data. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class DomainConverter { - - /** - * Replaces domain of WaveId. - * - * @param waveId source waveId - * @param waveDomain target wave domain - * @return wave id with waveDomain if waveDomain is not null, otherwise source wave id. - */ - public static WaveId convertWaveId(WaveId waveId, String waveDomain) { - if (waveDomain != null) { - return WaveId.of(waveDomain, waveId.getId()); - } - return waveId; - } - - /** - * Replaces domain of WaveletId. - * - * @param waveletId source waveletId - * @param waveDomain target wave domain - * @return wavelet id with waveDomain if waveDomain is not null, otherwise source wavelet id. - */ - public static WaveletId convertWaveletId(WaveletId waveletId, String waveDomain) throws InvalidParticipantAddress { - if (waveDomain != null) { - if (IdUtil.isUserDataWavelet(waveletId)) { - String sourceParticipant = IdUtil.getUserDataWaveletAddress(waveletId); - String targetParticipant = convertParticipantId(sourceParticipant, waveDomain).toString(); - String targetWaveletId = IdUtil.join(IdUtil.USER_DATA_WAVELET_PREFIX, targetParticipant); - return WaveletId.of(waveDomain, targetWaveletId); - } - return WaveletId.of(waveDomain, waveletId.getId()); - } - return waveletId; - } - - /** - * Replaces domain in deltas for Add/Remove participant operations. - * - * @param delta source delta - * @param waveDomain target wave domain - * @return delta for waveDomain if WaveDoamin is not null, otherwise source delta. - * @throws InvalidParticipantAddress if there is a problem with deserialization of participant id. - */ - public static ProtocolWaveletDelta convertDelta(ProtocolWaveletDelta delta, - String waveDomain) throws InvalidParticipantAddress { - if (waveDomain != null) { - ProtocolWaveletDelta.Builder newDelta = ProtocolWaveletDelta.newBuilder(delta); - ParticipantId author = convertParticipantId(delta.getAuthor(), waveDomain); - newDelta.setAuthor(author.getAddress()); - for (int i = 0; i < delta.getOperationCount(); i++) { - ProtocolWaveletOperation op = delta.getOperation(i); - ProtocolWaveletOperation.Builder newOp = ProtocolWaveletOperation.newBuilder(op); - if (op.hasAddParticipant()) { - convertAddParticipantOperation(newOp, op, waveDomain); - } else if (op.hasRemoveParticipant()) { - convertRemoveParticipantOperation(newOp, op, waveDomain); - } - // TODO(user) release convert for other operations. - newDelta.setOperation(i, newOp); - } - return newDelta.build(); - } else { - return delta; - } - } - - /** - * Converts all history deltas. - * - * @param deltas source deltas - * @param waveDomain target wave domain - * @return deltas for waveDomain if WaveDoamin is not null, otherwise source deltas. - * @throws InvalidParticipantAddress if there is a problem with deserialization of participant id. - */ - public static List<ProtocolWaveletDelta> convertDeltas(List<ProtocolWaveletDelta> deltas, - String waveDomain) throws InvalidParticipantAddress { - if (waveDomain != null) { - List<ProtocolWaveletDelta> targetDeltas = new LinkedList<ProtocolWaveletDelta>(); - for (ProtocolWaveletDelta delta : deltas) { - targetDeltas.add(DomainConverter.convertDelta(delta, waveDomain)); - } - return targetDeltas; - } else { - return deltas; - } - } - - /** - * Converts adding participant operation. - */ - private static void convertAddParticipantOperation(ProtocolWaveletOperation.Builder newOperation, - ProtocolWaveletOperation operation, String domain) throws InvalidParticipantAddress { - ParticipantId participant = convertParticipantId(operation.getAddParticipant(), domain); - newOperation.setAddParticipant(participant.getAddress()); - } - - /** - * Converts removal participant operation. - */ - private static void convertRemoveParticipantOperation(ProtocolWaveletOperation.Builder newOperation, - ProtocolWaveletOperation operation, String domain) throws InvalidParticipantAddress { - ParticipantId participant = convertParticipantId(operation.getRemoveParticipant(), domain); - newOperation.setRemoveParticipant(participant.getAddress()); - } - - /** - * Replaces participant domain. - */ - private static ParticipantId convertParticipantId(String participant, String domain) - throws InvalidParticipantAddress { - return ParticipantId.of(ParticipantId.of(participant).getName(), domain); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/FileNames.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/FileNames.java b/src/org/waveprotocol/box/expimp/FileNames.java deleted file mode 100644 index a2740f7..0000000 --- a/src/org/waveprotocol/box/expimp/FileNames.java +++ /dev/null @@ -1,106 +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.expimp; - -import org.waveprotocol.box.server.persistence.file.FileUtils; -import org.waveprotocol.wave.media.model.AttachmentId; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.id.InvalidIdException; - -import java.text.DecimalFormat; - -/** - * File and directory names for Export/Import utilities. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class FileNames { - private static final String FILE_NUMBER_PATTERN="000000"; - - private final String exportDir; - - public FileNames(String exportDir) { - this.exportDir = exportDir; - } - - public static String getWaveDirName(WaveId waveId) { - return FileUtils.waveIdToPathSegment(waveId); - } - - public static String getWaveletDirName(WaveletId waveletId) { - return FileUtils.waveletIdToPathSegment(waveletId); - } - - public static String getSnapshotFileName() { - return "snapshot.json"; - } - - public static String getDeltasFileName(int part) { - return "deltas." + new DecimalFormat(FILE_NUMBER_PATTERN).format(part) + ".json"; - } - - public static String getAttachmentsDirName() { - return "attachments"; - } - - public static String getAttachmentFileName(AttachmentId attachmentId) { - return attachmentId.serialise() + ".json"; - } - - public String getExportDir() { - return exportDir; - } - - public String getWaveDirPath(WaveId waveId) { - return exportDir + "/" + getWaveDirName(waveId); - } - - public String getWaveletDirPath(WaveId waveId, WaveletId waveletId) { - return getWaveDirPath(waveId) + "/" + getWaveletDirName(waveletId); - } - - public String getSnapshotFilePath(WaveId waveId, WaveletId waveletId) { - return getWaveletDirPath(waveId, waveletId) + "/" + getSnapshotFileName(); - } - - public String getDeltasFilePath(WaveId waveId, WaveletId waveletId, int part) { - return getWaveletDirPath(waveId, waveletId) + "/" + getDeltasFileName(part); - } - - public String getAttachmentsDirPath(WaveId waveId, WaveletId waveletId) { - return getWaveletDirPath(waveId, waveletId) + "/" + getAttachmentsDirName(); - } - - public String getAttachmentFilePath(WaveId waveId, WaveletId waveletId, AttachmentId attachmentId) { - return getAttachmentsDirPath(waveId, waveletId) + "/" + getAttachmentFileName(attachmentId); - } - - public static WaveId getWaveIdFromFileName(String name) { - return FileUtils.waveIdFromPathSegment(name); - } - - public static WaveletId getWaveletIdFromFileName(String name) { - return FileUtils.waveletIdFromPathSegment(name); - } - - public static AttachmentId getAttachmentIdFromFileName(String name) throws InvalidIdException { - return AttachmentId.deserialise(name.substring(0, name.length()-5)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/OAuth.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/OAuth.java b/src/org/waveprotocol/box/expimp/OAuth.java deleted file mode 100644 index 0e6fd22..0000000 --- a/src/org/waveprotocol/box/expimp/OAuth.java +++ /dev/null @@ -1,102 +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.expimp; - -import java.io.IOException; -import java.net.URLEncoder; -import java.util.StringTokenizer; - -import net.oauth.OAuthAccessor; -import net.oauth.OAuthConsumer; -import net.oauth.OAuthServiceProvider; - -import org.apache.commons.codec.binary.Base64; -import com.google.wave.api.WaveService; - -/** - * OAuth authorization through Robot and Data API. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class OAuth { - private static final String REQUEST_URL_POSTFIX = "/robot/dataapi/oauth/OAuthGetRequestToken"; - private static final String AUTH_URL_POSTFIX = "/robot/dataapi/oauth/OAuthAuthorizeToken"; - private static final String ACCESS_URL_POSTFIX = "/robot/dataapi/oauth/OAuthGetAccessToken"; - private static final String GET_ALL_TOKENS_URL_POSTFIX = "/robot/dataapi/oauth/OAuthGetAllTokens"; - - private static final String DATA_API_RPC_URL_POSTFIX = "/robot/dataapi/rpc"; - private static final String ROBOT_RPC_URL_POSTFIX = "/robot/rpc"; - - private static final String THREE_LEGGED_API_CONSUMER_KEY = "anonymous"; - private static final String THREE_LEGGED_API_CONSUMER_SECRET = "anonymous"; - - private final String serverUrl; - - public OAuth(String serverUrl) { - this.serverUrl = serverUrl; - } - - /** - * Performs 2-legged OAuth authorization through Robot API. - * - * @param service wave service. - * @param consumerKey robot consumer key. - * @param consumerSecret robot consumer secret. - */ - public String twoLeggedOAuth(WaveService service, String consumerKey, String consumerSecret) { - String rpcServerUrl = serverUrl + ROBOT_RPC_URL_POSTFIX; - service.setupOAuth(consumerKey, consumerSecret, rpcServerUrl); - return rpcServerUrl; - } - - /** - * Performs 3-legged OAuth authorization through Data API. - * - * @param service wave service. - */ - public String threeLeggedOAuth(WaveService service) throws IOException { - Console.println("Paste this URL in your browser:\n" + serverUrl + GET_ALL_TOKENS_URL_POSTFIX); - Console.println("Type the code you received here: "); - String authorizationCode = new String( - Base64.decodeBase64(Console.readLine().getBytes("UTF-8")), "UTF-8"); - - StringTokenizer st = new StringTokenizer(authorizationCode); - - String requestToken = st.nextToken(); - String accessToken = st.nextToken(); - String tokenSecret = st.nextToken(); - - String requestUrl = serverUrl + REQUEST_URL_POSTFIX; - String authUrl = serverUrl + AUTH_URL_POSTFIX; - String accessUrl = serverUrl + ACCESS_URL_POSTFIX; - - OAuthServiceProvider provider = new OAuthServiceProvider(requestUrl - + "?scope=" + URLEncoder.encode("", "utf-8"), authUrl, accessUrl); - OAuthConsumer consumer = new OAuthConsumer("", THREE_LEGGED_API_CONSUMER_KEY, - THREE_LEGGED_API_CONSUMER_SECRET, provider); - OAuthAccessor accessor = new OAuthAccessor(consumer); - accessor.requestToken = requestToken; - accessor.accessToken = accessToken; - accessor.tokenSecret = tokenSecret; - - String rpcServerUrl = serverUrl + DATA_API_RPC_URL_POSTFIX; - service.setupOAuth(accessor, rpcServerUrl); - return rpcServerUrl; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/WaveExport.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/WaveExport.java b/src/org/waveprotocol/box/expimp/WaveExport.java deleted file mode 100644 index 2108c1c..0000000 --- a/src/org/waveprotocol/box/expimp/WaveExport.java +++ /dev/null @@ -1,332 +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.expimp; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import org.waveprotocol.wave.communication.gson.GsonException; -import org.waveprotocol.wave.model.util.Base64DecoderException; -import com.google.wave.api.SearchResult; -import com.google.wave.api.SearchResult.Digest; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta; -import org.waveprotocol.wave.media.model.AttachmentId; -import org.waveprotocol.box.common.comms.proto.WaveletSnapshotProtoImpl; - -import com.google.wave.api.WaveService; -import com.google.wave.api.impl.GsonFactory; -import com.google.wave.api.impl.RawAttachmentData; - -import com.google.gson.Gson; -import com.google.gson.JsonParser; -import com.google.wave.api.impl.RawDeltasListener; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.FileWriter; -import java.util.LinkedList; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - -import org.waveprotocol.box.server.common.CoreWaveletOperationSerializer; -import org.waveprotocol.wave.federation.Proto.ProtocolHashedVersion; -import org.waveprotocol.wave.model.id.IdURIEncoderDecoder; -import org.waveprotocol.wave.model.id.WaveletName; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.version.HashedVersionFactory; -import org.waveprotocol.wave.model.version.HashedVersionFactoryImpl; -import org.waveprotocol.wave.util.escapers.jvm.JavaUrlCodec; - -/** - * Export waves from Wiab to files. - * - * @author [email protected] (Andrew Kaplanov) - */ -public class WaveExport { - private static final IdURIEncoderDecoder URI_CODEC = new IdURIEncoderDecoder(new JavaUrlCodec()); - private static final HashedVersionFactory HASH_FACTORY = new HashedVersionFactoryImpl(URI_CODEC); - - private static final Gson gson = new GsonFactory().create(); - private static final JsonParser jsonParser = new JsonParser(); - - private final String serverUrl; - private final WaveService api; - private final FileNames fileNames; - private String search = ""; - private String consumerKey; - private String consumerSecret; - private List<WaveId> includeList; - private List<WaveId> excludeList; - private String rpcServerUrl; - - public WaveExport(String serverUrl, String exportDir) { - this.serverUrl = serverUrl; - fileNames = new FileNames(exportDir); - api = new WaveService(); - api.setFetchFimeout(WaveService.FETCH_INFINITE_TIMEOUT); - } - - public static void usageError() { - Console.println("Use: WaveExport <server URL> <export directory>\n" - + " [-consumer_key Robot consumer key]\n" - + " [-consumer_secret Robot consumer secret]\n" - + " [-search Search query]\n" - + " [-include Include waves list]\n" - + " [-include_file Include waves list file]\n" - + " [-exclude Exclude waves list]"); - System.exit(1); - } - - public static void main(String[] args) throws IOException, Base64DecoderException { - if (args.length < 2) { - usageError(); - } - WaveExport export = new WaveExport(args[0], args[1]); - List<WaveId> includeList = new LinkedList<WaveId>(); - List<WaveId> excludeList = new LinkedList<WaveId>(); - for (int i = 2; i < args.length;) { - if (args[i].equals("-search")) { - export.setSearch(args[++i]); - i++; - } else if (args[i].equals("-consumer_key")) { - export.setConsumerKey(args[++i]); - i++; - } else if (args[i].equals("-consumer_secret")) { - export.setConsumerSecret(args[++i]); - i++; - } else if (args[i].equals("-include")) { - for (i = i + 1; i < args.length && args[i].charAt(0) != '-'; i++) { - includeList.add(WaveId.deserialise(args[i])); - } - } else if (args[i].equals("-include_file")) { - BufferedReader in = new BufferedReader(new FileReader(args[++i])); - for (;;) { - String line = in.readLine(); - if (line == null) - break; - includeList.add(WaveId.deserialise(line)); - } - in.close(); - i++; - } else if (args[i].equals("-exclude")) { - for (i = i + 1; i < args.length && args[i].charAt(0) != '-'; i++) { - excludeList.add(WaveId.deserialise(args[i])); - } - } else { - usageError(); - } - } - if (!includeList.isEmpty()) { - export.setIncludeList(includeList); - } - if (!excludeList.isEmpty()) { - export.setExcludeList(excludeList); - } - - export.authorization(); - export.exportWavesToFiles(); - } - - public void setSearch(String search) { - this.search = search; - } - - public void setConsumerKey(String consumerKey) { - this.consumerKey = consumerKey; - } - - public void setConsumerSecret(String consumerSecret) { - this.consumerSecret = consumerSecret; - } - - public void setExcludeList(List<WaveId> excludeList) { - this.excludeList = excludeList; - } - - public void setIncludeList(List<WaveId> includeList) { - this.includeList = includeList; - } - - /** - * Performs authorization. - */ - public void authorization() throws IOException, Base64DecoderException { - OAuth oauth = new OAuth(serverUrl); - if (consumerKey != null && consumerSecret != null) { - rpcServerUrl = oauth.twoLeggedOAuth(api, consumerKey, consumerSecret); - } else { - rpcServerUrl = oauth.threeLeggedOAuth(api); - } - } - - /** - * Exports waves to files. - */ - private void exportWavesToFiles() throws IOException { - Console.println(); - List<WaveId> waves = includeList; - if (waves == null || waves.isEmpty()) { - waves = getAllWavesList(); - } - int exportedCount = 0; - int failedCount = 0; - for (int i = 0; i < waves.size(); i++) { - boolean errorOccured = false; - WaveId waveId = waves.get(i); - try { - if (excludeList != null && excludeList.contains(waveId)) { - Console.println("Skipping wave " + waveId.serialise() + "..."); - continue; - } - Console.println("Exporting wave " + waveId.serialise() - + " (" + (i + 1) + " of " + waves.size() + ") ..."); - new File(fileNames.getWaveDirPath(waveId)).mkdir(); - for (WaveletId waveletId : api.retrieveWaveletIds(waveId, rpcServerUrl)) { - WaveletSnapshotProtoImpl snapshot = exportSnapshot(waveId, waveletId); - Set<AttachmentId> attachmentIds = new HashSet<AttachmentId>(); - try { - exportDeltas(waveId, waveletId, snapshot.getVersion().getPB(), attachmentIds); - } catch (IOException ex) { - errorOccured = true; - Console.error("Export of deltas error.", ex); - } - if (!attachmentIds.isEmpty()) { - new File(fileNames.getAttachmentsDirPath(waveId, waveletId)).mkdir(); - for (AttachmentId attachmentId : attachmentIds) { - try { - exportAttachment(waveId, waveletId, attachmentId); - } catch (IOException ex) { - errorOccured = true; - Console.error("Uploading of attachment error.", ex); - } - } - } - } - } catch (Exception ex) { - errorOccured = true; - Console.error("Exporting of " + waveId.serialise() + " error.", ex); - } - if (errorOccured) { - failedCount++; - } else { - exportedCount++; - } - } - Console.println(); - Console.println("Successfully exported " + exportedCount + " waves."); - Console.println("Failed for " + failedCount + " waves."); - } - - private WaveletSnapshotProtoImpl exportSnapshot(WaveId waveId, WaveletId waveletId) - throws IOException { - new File(fileNames.getWaveletDirPath(waveId, waveletId)).mkdir(); - Console.println(" wavelet " + waveletId.serialise()); - Console.print(" getting snapshot ..."); - String snapshotJSon = api.exportRawSnapshot(waveId, waveletId, rpcServerUrl); - writeSnapshotToFile(waveId, waveletId, snapshotJSon); - WaveletSnapshotProtoImpl snapshot = new WaveletSnapshotProtoImpl(); - try { - snapshot.fromGson(jsonParser.parse(snapshotJSon), gson, null); - } catch (GsonException ex) { - throw new IOException(ex); - } - Console.println(" Ok, version " + (long)snapshot.getVersion().getVersion()); - return snapshot; - } - - private void exportDeltas(WaveId waveId, WaveletId waveletId, ProtocolHashedVersion lastVersion, - Set<AttachmentId> attachmentIds) throws IOException { - HashedVersion zeroVersion = HASH_FACTORY.createVersionZero(WaveletName.of(waveId, waveletId)); - ProtocolHashedVersion version = CoreWaveletOperationSerializer.serialize(zeroVersion); - for (int fetchNum = 0; version.getVersion() != lastVersion.getVersion(); fetchNum++) { - Console.print(" getting deltas from version " + version.getVersion() + " ..."); - final List<byte[]> deltas = Lists.newArrayList(); - final AtomicReference<byte[]> targetVersion = new AtomicReference<byte[]>(); - api.exportRawDeltas(waveId, waveletId, - version.toByteArray(), lastVersion.toByteArray(), rpcServerUrl, new RawDeltasListener() { - @Override - public void onSuccess(List<byte[]> rawDeltas, byte[] rawTargetVersion) { - deltas.addAll(rawDeltas); - targetVersion.set(rawTargetVersion); - } - - @Override - public void onFailire(String message) { - Console.error(search); - } - }); - if (deltas.isEmpty()) { - Console.println(" empty response"); - continue; - } - version = ProtocolHashedVersion.parseFrom(targetVersion.get()); - Console.println(" Ok, got to version " + version.getVersion()); - writeDeltasToFile(waveId, waveletId, deltas, fetchNum); - for (byte[] delta : deltas) { - attachmentIds.addAll(DeltaParser.getAttachemntIds(ProtocolWaveletDelta.parseFrom(delta))); - } - } - } - - private void exportAttachment(WaveId waveId, WaveletId waveletId, AttachmentId attachmentId) throws IOException { - Console.print(" getting attachment " + attachmentId.getId() + " ..."); - RawAttachmentData attachment = api.exportAttachment(attachmentId, rpcServerUrl); - writeAttachmentToFile(waveId, waveletId, attachmentId, attachment); - Console.println(" Ok"); - } - - private List<WaveId> getAllWavesList() throws IOException { - List<WaveId> allList = new LinkedList<WaveId>(); - SearchResult result = api.search(search, 0, Integer.MAX_VALUE, rpcServerUrl); - for (Digest digest : result.getDigests()) { - allList.add(WaveId.deserialise(digest.getWaveId())); - } - return allList; - } - - private void writeSnapshotToFile(WaveId waveId, WaveletId waveletId, String snapshot) throws IOException { - String fileName = fileNames.getSnapshotFilePath(waveId, waveletId); - writeFile(fileName, snapshot); - } - - private void writeDeltasToFile(WaveId waveId, WaveletId waveletId, List<byte[]> deltas, - int fetchNum) throws IOException { - String fileName = fileNames.getDeltasFilePath(waveId, waveletId, fetchNum); - String gsonStr = gson.toJson(deltas); - writeFile(fileName, gsonStr); - } - - private void writeAttachmentToFile(WaveId waveId, WaveletId waveletId, AttachmentId attachmentId, - RawAttachmentData attachment) throws IOException { - String fileName = fileNames.getAttachmentFilePath(waveId, waveletId, attachmentId); - String gsonStr = gson.toJson(attachment); - writeFile(fileName, gsonStr); - } - - static private void writeFile(String name, String data) throws IOException { - FileWriter w = new FileWriter(new File(name)); - w.write(data); - w.close(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/expimp/WaveImport.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/expimp/WaveImport.java b/src/org/waveprotocol/box/expimp/WaveImport.java deleted file mode 100644 index 430082b..0000000 --- a/src/org/waveprotocol/box/expimp/WaveImport.java +++ /dev/null @@ -1,294 +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.expimp; - -import com.google.gson.Gson; -import com.google.protobuf.ByteString; -import com.google.wave.api.WaveService; -import com.google.wave.api.impl.RawAttachmentData; -import com.google.wave.api.impl.GsonFactory; - -import org.waveprotocol.wave.media.model.AttachmentId; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.id.IdUtil; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta; -import org.waveprotocol.wave.model.wave.InvalidParticipantAddress; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * Import waves from files to Wiab. - * - * @author ([email protected]) (Andrew Kaplanov) - */ -public final class WaveImport { - - private enum ImportWaveletState { NOTHING_DONE, WAVELET_CREATED, WAVELET_UPDATED }; - - private static final Gson gson = new GsonFactory().create(); - - private final String serverUrl; - private final WaveService api; - private final FileNames fileNames; - - private String consumerKey; - private String consumerSecret; - private String rpcServerUrl; - private String waveDomain; - - static public void usageError() { - Console.println("Use: WaveImport <server URL> <export directory>\n" - + " [-consumer_key Robot consumer key]\n" - + " [-consumer_secret Robot consumer secret]\n" - + " [-wave_domain Target wave domain]"); - System.exit(1); - } - - public static void main(String[] args) throws IOException { - if (args.length < 2) { - usageError(); - } - WaveImport imp = new WaveImport(args[0], args[1]); - for (int i = 2; i < args.length;) { - if (args[i].equals("-consumer_key")) { - imp.setConsumerKey(args[++i]); - i++; - } else if (args[i].equals("-consumer_secret")) { - imp.setConsumerSecret(args[++i]); - i++; - } else if (args[i].equals("-wave_domain")) { - imp.setWaveDomain(args[++i]); - i++; - } else { - usageError(); - } - } - imp.authorization(); - imp.importWavesFromFiles(); - } - - private WaveImport(String serverUrl, String exportDir) { - this.serverUrl = serverUrl; - fileNames = new FileNames(exportDir); - api = new WaveService(); - api.setFetchFimeout(WaveService.FETCH_INFINITE_TIMEOUT); - } - - public void setConsumerKey(String consumerKey) { - this.consumerKey = consumerKey; - } - - public void setConsumerSecret(String consumerSecret) { - this.consumerSecret = consumerSecret; - } - - public void setWaveDomain(String waveDomain) { - this.waveDomain = waveDomain; - } - - /** - * Performs authorization. - */ - public void authorization() throws IOException { - OAuth oauth = new OAuth(serverUrl); - if (consumerKey != null && consumerSecret != null) { - rpcServerUrl = oauth.twoLeggedOAuth(api, consumerKey, consumerSecret); - } else { - rpcServerUrl = oauth.threeLeggedOAuth(api); - } - } - - /** - * Imports waves from files. - */ - public void importWavesFromFiles() { - Console.println(); - File expDir = new File(fileNames.getExportDir()); - if (!expDir.exists()) { - Console.println("Directory " + fileNames.getExportDir() + " is not exists."); - System.exit(1); - } - File[] waveDirs = expDir.listFiles(); - Arrays.sort(waveDirs, new Comparator<File>() { - - @Override - public int compare(File f1, File f2) { - return f1.getName().compareTo(f2.getName()); - } - }); - int createdCount = 0; - int updatedCount = 0; - int skippedCount = 0; - int failedCount = 0; - for (int i = 0; i < waveDirs.length; i++) { - File waveDir = waveDirs[i]; - WaveId sourceWaveId = FileNames.getWaveIdFromFileName(waveDir.getName()); - WaveId targetWaveId = DomainConverter.convertWaveId(sourceWaveId, waveDomain); - Console.println("Importing wave " + targetWaveId.serialise() - + " (" + (i + 1) + " of " + waveDirs.length + ") ..."); - boolean waveCreated = false; - boolean waveUpdated = false; - File[] waveletDirs = waveDir.listFiles(); - for (File waveletDir : waveletDirs) { - WaveletId sourceWaveletId = FileNames.getWaveletIdFromFileName(waveletDir.getName()); - try { - ImportWaveletState state = importWavelet(sourceWaveId, sourceWaveletId); - if (state == ImportWaveletState.WAVELET_CREATED && !IdUtil.isUserDataWavelet(sourceWaveletId)) { - waveCreated = true; - } else if (state != ImportWaveletState.NOTHING_DONE) { - waveUpdated = true; - } - } catch (IOException ex) { - failedCount++; - Console.error("Importing wavelet error", ex); - } - } - if (waveCreated) { - createdCount++; - } else if (waveUpdated) { - updatedCount++; - } else { - skippedCount++; - } - } - Console.println(); - Console.println("Created " + createdCount + " waves."); - Console.println("Updated " + updatedCount + " waves."); - Console.println("Skipped " + skippedCount + " waves."); - Console.println("Failed for " + failedCount + " waves."); - } - - private ImportWaveletState importWavelet(WaveId sourceWaveId, WaveletId sourceWaveletId) - throws IOException { - ImportWaveletState state = ImportWaveletState.NOTHING_DONE; - WaveId targetWaveId = DomainConverter.convertWaveId(sourceWaveId, waveDomain); - WaveletId targetWaveletId; - try { - targetWaveletId = DomainConverter.convertWaveletId(sourceWaveletId, waveDomain); - } catch (InvalidParticipantAddress ex) { - throw new IOException(ex); - } - Set<AttachmentId> attachmentIds = new HashSet<AttachmentId>(); - Console.println(" wavelet " + targetWaveletId.serialise()); - for (int part=0 ; ; part++) { - File deltasFile = new File(fileNames.getDeltasFilePath(sourceWaveId, sourceWaveletId, part)); - if (!deltasFile.exists()) { - break; - } - ImportWaveletState st = importDeltas(deltasFile, targetWaveId, targetWaveletId, attachmentIds); - if (state == ImportWaveletState.NOTHING_DONE) { - state = st; - } - } - importAttachments(sourceWaveId, sourceWaveletId, targetWaveId, targetWaveletId, attachmentIds); - return state; - } - - private ImportWaveletState importDeltas(File deltasFile, WaveId targetWaveId, WaveletId targetWaveletId, - Set<AttachmentId> attachmentIds) throws IOException { - ImportWaveletState state = ImportWaveletState.NOTHING_DONE; - @SuppressWarnings("unchecked") - List<byte[]> sourceHistory = gson.fromJson(readFile(deltasFile), GsonFactory.RAW_DELTAS_TYPE); - List<byte[]> targetHistory; - List<ProtocolWaveletDelta> deltas = DeltaParser.parseDeltas(sourceHistory); - List<ProtocolWaveletDelta> targetDeltas; - if (waveDomain != null) { - try { - targetDeltas = DomainConverter.convertDeltas(deltas, waveDomain); - } catch (InvalidParticipantAddress ex) { - throw new IOException(ex); - } - targetHistory = new LinkedList<byte[]>(); - for (ProtocolWaveletDelta delta : targetDeltas) { - targetHistory.add(delta.toByteArray()); - } - } else { - targetDeltas = deltas; - targetHistory = sourceHistory; - } - if (!targetDeltas.isEmpty()) { - long fromVersion = targetDeltas.get(0).getHashedVersion().getVersion(); - ProtocolWaveletDelta lastDelta = targetDeltas.get(targetDeltas.size()-1); - long toVersion = lastDelta.getHashedVersion().getVersion()+lastDelta.getOperationCount(); - Console.print(" send deltas " + fromVersion + "-" + toVersion + " ..."); - long importedFromVersion = api.importRawDeltas(targetWaveId, targetWaveletId, targetHistory, rpcServerUrl); - if (fromVersion == importedFromVersion) { - Console.println(" imported"); - } else if (importedFromVersion == -1) { - Console.println(" skipped"); - } else { - Console.println(" imported from version " + importedFromVersion); - } - if (fromVersion == importedFromVersion) { - if (fromVersion == 0) { - state = ImportWaveletState.WAVELET_CREATED; - } else { - state = ImportWaveletState.WAVELET_UPDATED; - } - } else if (importedFromVersion != -1) { - state = ImportWaveletState.WAVELET_UPDATED; - } - if (importedFromVersion != -1) { - for (ProtocolWaveletDelta delta : targetDeltas) { - if (delta.getHashedVersion().getVersion() >= importedFromVersion) { - attachmentIds.addAll(DeltaParser.getAttachemntIds(delta)); - } - } - } - } - return state; - } - - private void importAttachments(WaveId sourceWaveId, WaveletId sourceWaveletId, - WaveId targetWaveId, WaveletId targetWaveletId, Set<AttachmentId> attachmentIds) - throws FileNotFoundException, IOException { - for (AttachmentId attachmentId : attachmentIds) { - String attachmentFile = fileNames.getAttachmentFilePath(sourceWaveId, sourceWaveletId, attachmentId); - RawAttachmentData attachmentData = gson.fromJson(readFile(new File(attachmentFile)), RawAttachmentData.class); - Console.print(" importing attachment " + attachmentId.serialise() + " ..."); - api.importAttachment(targetWaveId, targetWaveletId, attachmentId, attachmentData, rpcServerUrl); - Console.println(" Ok"); - } - } - - private static String readFile(File file) throws FileNotFoundException, IOException { - Reader reader = new FileReader(file); - StringBuilder sb = new StringBuilder(); - char buf[] = new char[1024]; - for (;;) { - int ret = reader.read(buf, 0, buf.length); - if (ret == -1) { - break; - } - sb.append(buf, 0, ret); - } - return sb.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/profile/Profile.gwt.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/profile/Profile.gwt.xml b/src/org/waveprotocol/box/profile/Profile.gwt.xml deleted file mode 100644 index b02f733..0000000 --- a/src/org/waveprotocol/box/profile/Profile.gwt.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version='1.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. - ---> - -<module> - <!-- DTO deps below. --> - <inherits name="org.waveprotocol.wave.communication.Communication"/> - <source path="" excludes="gson/** proto/**"/> - <source path=""/> -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/profile/profiles.proto ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/profile/profiles.proto b/src/org/waveprotocol/box/profile/profiles.proto deleted file mode 100644 index 4370ee1..0000000 --- a/src/org/waveprotocol/box/profile/profiles.proto +++ /dev/null @@ -1,51 +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. -// -// The profile fetch request and response. -// -// Author: [email protected] (Yuri Zelikov) - -syntax = "proto2"; - -package profile; - -option java_package = "org.waveprotocol.box.profile"; -option java_outer_classname = "ProfilesProto"; - - -message ProfileRequest { - // The profile addresses in email format. - repeated string addresses = 1; -} - -message ProfileResponse { - - message FetchedProfile { - // The profile address in email format. - required string address = 1; - // The name. - required string name = 2; - // The image URL. - required string imageUrl = 3; - // The link to website. - optional string profileUrl = 4; - } - - // The fetched profiles. - repeated FetchedProfile profiles = 1; -} - http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/search/Search.gwt.xml ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/search/Search.gwt.xml b/src/org/waveprotocol/box/search/Search.gwt.xml deleted file mode 100644 index 7393ff6..0000000 --- a/src/org/waveprotocol/box/search/Search.gwt.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version='1.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. - ---> - -<module> - <inherits name="org.waveprotocol.wave.federation.Federation"/> - <!-- DTO deps below. --> - <inherits name="org.waveprotocol.wave.communication.Communication"/> - <source path="" excludes="gson/** proto/**"/> -</module> http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/search/search.proto ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/search/search.proto b/src/org/waveprotocol/box/search/search.proto deleted file mode 100644 index 889ee05..0000000 --- a/src/org/waveprotocol/box/search/search.proto +++ /dev/null @@ -1,68 +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. -// -// The search query and response. -// -// Author: [email protected] (Yuri Z.) - -syntax = "proto2"; - -package search; - -option java_package = "org.waveprotocol.box.search"; -option java_outer_classname = "SearchProto"; - - -message SearchRequest { - // The query to execute. - required string query = 1; - // The index from which to return results. - required int32 index = 2; - // The number of results to return. - required int32 numResults = 3; -} - -message SearchResponse { - // The wave list digest. - message Digest { - // The wave title. - required string title = 1; - // The text snippet. - required string snippet = 2; - // Serialized wave id - required string waveId = 3; - // Last modified time of the wave. - required int64 lastModified = 4; - // Unread count for the user. - required int32 unreadCount = 5; - // Number of blips in the wave. - required int32 blipCount = 6; - // Wave participants. - repeated string participants = 7; - // The wave author. - required string author = 8; - } - - // The search query. - required string query = 1; - // The total number of results to the query (not necessarily all returned). - required int32 totalResults = 2; - // A list of digests, representing the segment [index, index + result_count] - // from the query parameters. - repeated Digest digests = 3; -} - http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/server/CoreSettingsNames.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/CoreSettingsNames.java b/src/org/waveprotocol/box/server/CoreSettingsNames.java deleted file mode 100644 index 9179951..0000000 --- a/src/org/waveprotocol/box/server/CoreSettingsNames.java +++ /dev/null @@ -1,27 +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. - */ - - /** - * @author [email protected](Yuri Zelikov) - */ -package org.waveprotocol.box.server; - -public interface CoreSettingsNames { - String WAVE_SERVER_DOMAIN = "wave_server_domain"; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/server/DataMigrationTool.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/DataMigrationTool.java b/src/org/waveprotocol/box/server/DataMigrationTool.java deleted file mode 100644 index 0ec107b..0000000 --- a/src/org/waveprotocol/box/server/DataMigrationTool.java +++ /dev/null @@ -1,141 +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; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.waveprotocol.box.server.persistence.PersistenceModule; -import org.waveprotocol.box.server.persistence.migration.DeltaMigrator; -import org.waveprotocol.box.server.waveserver.DeltaStore; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -/** - * A cmd line utility to perform data migration from a store type to another - * one. Initially developed to replicate deltas from a file store to a mongodb - * store. - * - * - * @author [email protected] (Pablo Ojanguren) - * - */ -public class DataMigrationTool { - - private static void runDeltasMigration(Injector sourceInjector, Injector targetInjector) { - - // We can migrate data from-to any store type, - // but it is not allowed migrate from-to the same type - String sourceDeltaStoreType = - sourceInjector - .getInstance(Config.class).getString("core.delta_store_type"); - - String targetDeltaStoreType = - targetInjector - .getInstance(Config.class).getString("core.delta_store_type"); - - if (sourceDeltaStoreType.equalsIgnoreCase(targetDeltaStoreType)) - usageError("Source and Target Delta store types must be different"); - - - DeltaMigrator dm = - new DeltaMigrator(sourceInjector.getInstance(DeltaStore.class), - targetInjector.getInstance(DeltaStore.class)); - - dm.run(); - - } - - private static Module bindCmdLineSettings(String cmdLineProperties) { - - // Get settings from cmd line, e.g. - // Key = delta_store_type - // Value = mongodb - final Map<String, String> propertyMap = new HashMap<>(); - - for (String arg : cmdLineProperties.split(",")) { - String[] argTokens = arg.split("="); - propertyMap.put(argTokens[0], argTokens[1]); - } - - return new AbstractModule() { - - @Override - protected void configure() { - Config config = ConfigFactory.load().withFallback( - ConfigFactory.parseFile(new File("application.conf")).withFallback( - ConfigFactory.parseFile(new File("reference.conf")))); - bind(Config.class).toInstance(ConfigFactory.parseMap(propertyMap).withFallback(config)); - } - }; - - } - - public static void usageError() { - usageError(""); - } - - public static void usageError(String msg) { - System.out.println(msg + "\n"); - System.out.println("Use: DataMigrationTool <data type> <source options> <target options>\n"); - System.out.println("supported data types : deltas"); - System.out - .println("source options example : core.delta_store_type=file," + - "core.delta_store_directory=_deltas"); - System.out - .println("target options example : core.delta_store_type=mongodb," + - "core.mongodb_host=127.0.0.1,core.mongodb_port=27017,core.mongodb_database=wiab"); - System.exit(1); - } - - public static void main(String... args) { - - if (args.length != 3) usageError(); - - String dataType = args[0]; - - Module sourceSettings = bindCmdLineSettings(args[1]); - Injector sourceSettingsInjector = Guice.createInjector(sourceSettings); - Module sourcePersistenceModule = sourceSettingsInjector.getInstance(PersistenceModule.class); - Injector sourceInjector = sourceSettingsInjector.createChildInjector(sourcePersistenceModule); - - - Module targetSettings = bindCmdLineSettings(args[2]); - Injector targetSettingsInjector = Guice.createInjector(targetSettings); - Module targetPersistenceModule = targetSettingsInjector.getInstance(PersistenceModule.class); - Injector targetInjector = targetSettingsInjector.createChildInjector(targetPersistenceModule); - - - if (dataType.equals("deltas")) { - runDeltasMigration(sourceInjector, targetInjector); - - } else { - usageError("Wrong data type"); - } - - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/org/waveprotocol/box/server/SearchModule.java ---------------------------------------------------------------------- diff --git a/src/org/waveprotocol/box/server/SearchModule.java b/src/org/waveprotocol/box/server/SearchModule.java deleted file mode 100644 index 4422155..0000000 --- a/src/org/waveprotocol/box/server/SearchModule.java +++ /dev/null @@ -1,82 +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; - -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.persistence.file.FileUtils; -import org.waveprotocol.box.server.persistence.lucene.FSIndexDirectory; -import org.waveprotocol.box.server.persistence.lucene.IndexDirectory; -import org.waveprotocol.box.server.waveserver.*; - -/** - * @author [email protected] (Yuri Zelikov) - */ -public class SearchModule extends AbstractModule { - - private final String searchType; - private final String indexDirectory; - - @Inject - public SearchModule(Config config) { - this.searchType = config.getString("core.search_type"); - this.indexDirectory = config.getString("core.index_directory"); - } - - @Override - public void configure() { - if ("lucene".equals(searchType)) { - bind(SearchProvider.class).to(SimpleSearchProviderImpl.class).in(Singleton.class); - bind(PerUserWaveViewProvider.class).to(LucenePerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(PerUserWaveViewBus.Listener.class).to(LucenePerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(PerUserWaveViewHandler.class).to(LucenePerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(IndexDirectory.class).to(FSIndexDirectory.class); - if (!FileUtils.isDirExistsAndNonEmpty(indexDirectory)) { - bind(WaveIndexer.class).to(LuceneWaveIndexerImpl.class); - } else { - bind(WaveIndexer.class).to(NoOpWaveIndexerImpl.class); - } - } else if ("solr".equals(searchType)) { - bind(SearchProvider.class).to(SolrSearchProviderImpl.class).in(Singleton.class); - /*- - * (Frank R.) binds to class with dummy methods just because it's required by - * org.waveprotocol.box.server.ServerMain.initializeSearch(Injector, WaveBus) - */ - bind(PerUserWaveViewBus.Listener.class).to(SolrWaveIndexerImpl.class).in(Singleton.class); - bind(WaveIndexer.class).to(SolrWaveIndexerImpl.class).in(Singleton.class); - } else if ("memory".equals(searchType)) { - bind(SearchProvider.class).to(SimpleSearchProviderImpl.class).in(Singleton.class); - bind(PerUserWaveViewProvider.class).to(MemoryPerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(PerUserWaveViewBus.Listener.class).to(MemoryPerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(PerUserWaveViewHandler.class).to(MemoryPerUserWaveViewHandlerImpl.class).in( - Singleton.class); - bind(WaveIndexer.class).to(MemoryWaveIndexerImpl.class).in(Singleton.class); - } else { - throw new RuntimeException("Unknown search type: " + searchType); - } - } -}
