Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
U-D03\BarthaM authored and U-D03\BarthaM committed Oct 28, 2015
2 parents 447eb62 + e989e91 commit 268d1fa
Show file tree
Hide file tree
Showing 130 changed files with 6,037 additions and 4,225 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
*/autodeploy/*
build/*
*/osgiTmp/*
.metadata
RemoteSystemsTempFiles

# Maven
target/
Expand All @@ -12,9 +10,13 @@ target/
*.iml

# Eclipse
.metadata
.classpath
.project
.pydevproject
.settings/
RemoteSystemsTempFiles/
.recommenders

# Mac OS X
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;

import org.backmeup.model.exceptions.PluginException;
import org.backmeup.plugin.spi.OAuthBasedAuthorizable;
import org.backmeup.plugin.api.OAuthBasedAuthorizable;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.DropboxAPI.Entry;
Expand All @@ -25,7 +25,7 @@ public class DropboxAuthenticator implements OAuthBasedAuthorizable {

@Override
public AuthorizationType getAuthType() {
return AuthorizationType.OAuth;
return AuthorizationType.OAUTH;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.backmeup.model.dto.PluginProfileDTO;
import org.backmeup.model.exceptions.PluginException;
import org.backmeup.plugin.api.connectors.Datasink;
import org.backmeup.plugin.api.connectors.Progressable;
import org.backmeup.plugin.api.Datasink;
import org.backmeup.plugin.api.PluginContext;
import org.backmeup.plugin.api.Progressable;
import org.backmeup.plugin.api.storage.DataObject;
import org.backmeup.plugin.api.storage.Storage;
import org.backmeup.plugin.api.storage.StorageException;
Expand All @@ -24,11 +24,10 @@
*/
public class DropboxDatasink implements Datasink {
@Override
public String upload(Map<String, String> authData, Map<String, String> properties,
List<String> options, Storage storage, Progressable progressor)
public String upload(PluginProfileDTO pluginProfile, PluginContext context, Storage storage, Progressable progressor)
throws StorageException {

DropboxAPI<WebAuthSession> api = DropboxHelper.getInstance().getApi(authData);
DropboxAPI<WebAuthSession> api = DropboxHelper.getInstance().getApi(pluginProfile.getAuthData());
Iterator<DataObject> it = storage.getDataObjects();
while (it.hasNext()) {
DataObject dataObj = it.next();
Expand All @@ -40,8 +39,8 @@ public String upload(Map<String, String> authData, Map<String, String> propertie
String tmpDir;
// TODO: do we really get this in properties (before it was
// "items")?
if (properties.containsKey("org.backmeup.tmpdir") == true) {
tmpDir = properties.get("org.backmeup.tmpdir");
if (context.hasAttribute("org.backmeup.tmpdir")) {
tmpDir = context.getAttribute("org.backmeup.tmpdir", String.class);
} else {
throw new PluginException(DropboxDescriptor.DROPBOX_ID,
"Property \"org.backmeup.tmpdir\" is not set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import org.backmeup.model.ValidationNotes;
import org.backmeup.model.api.RequiredInputField;
import org.backmeup.model.dto.PluginProfileDTO;
import org.backmeup.model.exceptions.PluginException;
import org.backmeup.model.spi.Validationable;
import org.backmeup.plugin.api.FilesystemLikeDatasource;
import org.backmeup.plugin.api.FilesystemURI;
import org.backmeup.plugin.api.Metainfo;
import org.backmeup.plugin.api.connectors.FilesystemLikeDatasource;
import org.backmeup.plugin.api.connectors.FilesystemURI;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.DropboxAPI.Entry;
Expand Down Expand Up @@ -50,9 +51,9 @@ private boolean beginsWith(List<String> collection, String beginner) {
}

@Override
public List<FilesystemURI> list(Map<String, String> accessData, List<String> options, FilesystemURI uri) {
public List<FilesystemURI> list(PluginProfileDTO pluginProfile, FilesystemURI uri) {
String path = uri == null ? "/" : uri.toString();
DropboxAPI<WebAuthSession> api = DropboxHelper.getInstance().getApi(accessData);
DropboxAPI<WebAuthSession> api = DropboxHelper.getInstance().getApi(pluginProfile.getAuthData());
List<FilesystemURI> uris = new ArrayList<>();

try {
Expand Down Expand Up @@ -86,6 +87,7 @@ public List<FilesystemURI> list(Map<String, String> accessData, List<String> opt
meta.setSource(DROPBOX);
meta.setType(e.isDir ? "directory" : new MimetypesFileTypeMap().getContentType(e.path));
furi.addMetainfo(meta);
List<String> options = pluginProfile.getOptions();
if (options == null || options.isEmpty() || beginsWith(options, e.path.replace(" ", "%20"))) {
uris.add(furi);
}
Expand All @@ -112,16 +114,15 @@ public List<FilesystemURI> list(Map<String, String> accessData, List<String> opt
}

@Override
public InputStream getFile(Map<String, String> accessData, List<String> options,
FilesystemURI uri) {
public InputStream getFile(PluginProfileDTO pluginProfile, FilesystemURI uri) {
String path = "";
try {
try {
path = URLDecoder.decode(uri.toString(), "UTF-8");
} catch (Exception ex) {
ex.printStackTrace();
}
return DropboxHelper.getInstance().getApi(accessData)
return DropboxHelper.getInstance().getApi(pluginProfile.getAuthData())
.getFileStream(path, null);
} catch (DropboxServerException e) {
// Handle undocumented error 460 (Restricted).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Map;

import org.backmeup.model.exceptions.PluginException;
import org.backmeup.plugin.api.BaseSourceSinkDescribable;
import org.backmeup.plugin.api.Metadata;
import org.backmeup.plugin.api.connectors.BaseSourceSinkDescribable;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.session.WebAuthSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;
import java.util.Properties;

import org.backmeup.model.dto.AuthDataDTO;
import org.backmeup.model.exceptions.InvalidKeyException;
import org.backmeup.model.exceptions.PluginException;

Expand Down Expand Up @@ -57,6 +58,10 @@ public WebAuthSession getWebAuthSession() {
return new WebAuthSession(appKeys, AccessType.DROPBOX);
}

public DropboxAPI<WebAuthSession> getApi(AuthDataDTO authData) {
return getApi(authData.getProperties());
}

public DropboxAPI<WebAuthSession> getApi(Map<String, String> accessData) {
String token = accessData.get(DropboxHelper.PROPERTY_ACCESS_TOKEN);
String secret = accessData.get(DropboxHelper.PROPERTY_ACCESS_SECRET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.backmeup.dropbox.DropboxDatasource;
import org.backmeup.plugin.api.connectors.Progressable;
import org.backmeup.model.dto.PluginProfileDTO;
import org.backmeup.plugin.api.PluginContext;
import org.backmeup.plugin.api.Progressable;
import org.backmeup.plugin.api.storage.DataObject;
import org.backmeup.plugin.api.storage.Storage;
import org.backmeup.plugin.api.storage.StorageException;
Expand All @@ -30,7 +31,7 @@ public static void main(String[] args) throws IOException, StorageException {
DropboxDatasource source = new DropboxDatasource();
Storage storage = new LocalFilesystemStorage();
storage.open("C:/TEMP/TEST/");
source.downloadAll(authData, new HashMap<String, String>(), new ArrayList<String>(), storage, new Progressable() {
source.downloadAll(new PluginProfileDTO(), new PluginContext(), storage, new Progressable() {
@Override
public void progress(String message) {}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.Map;

import org.backmeup.plugin.spi.OAuthBasedAuthorizable;
import org.backmeup.plugin.api.OAuthBasedAuthorizable;

public class DummyAuthenticator implements OAuthBasedAuthorizable {

@Override
public AuthorizationType getAuthType() {
return AuthorizationType.OAuth;
return AuthorizationType.OAUTH;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package org.backmeup.dummy;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.backmeup.model.dto.PluginProfileDTO;
import org.backmeup.plugin.api.Datasink;
import org.backmeup.plugin.api.Metainfo;
import org.backmeup.plugin.api.connectors.Datasink;
import org.backmeup.plugin.api.connectors.Progressable;
import org.backmeup.plugin.api.PluginContext;
import org.backmeup.plugin.api.Progressable;
import org.backmeup.plugin.api.storage.DataObject;
import org.backmeup.plugin.api.storage.Storage;
import org.backmeup.plugin.api.storage.StorageException;

public class DummyDatasink implements Datasink {

@Override
public String upload(Map<String, String> authData, Map<String, String> properties, List<String> options, Storage storage, Progressable progressor) throws StorageException {
public String upload(PluginProfileDTO pluginProfile, PluginContext context, Storage storage, Progressable progressor) throws StorageException {

System.out.println("Uploading to StorageReader");
progressor.progress("Uploading to StorageReader");

Iterator<DataObject> it = storage.getDataObjects();
while (it.hasNext()) {
DataObject obj = it.next();
Iterator<Metainfo> infos = obj.getMetainfo().iterator();
if (infos.hasNext()) {
System.out.println("=============================================");
System.out.println("Metainfos of object:\t\t" + obj.getPath());
progressor.progress("=============================================");
progressor.progress("Metainfos of object:\t\t" + obj.getPath());
while (infos.hasNext()) {
Metainfo info = infos.next();
for (Entry<Object, Object> entry : info.getAttributes().entrySet()) {
System.out.println(entry.getKey() + ":\t\t" + entry.getValue());
progressor.progress(entry.getKey() + ":\t\t" + entry.getValue());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,38 @@

import org.backmeup.model.ValidationNotes;
import org.backmeup.model.api.RequiredInputField;
import org.backmeup.model.dto.PluginProfileDTO;
import org.backmeup.model.exceptions.PluginException;
import org.backmeup.model.spi.ValidationExceptionType;
import org.backmeup.model.spi.Validationable;
import org.backmeup.plugin.api.Datasource;
import org.backmeup.plugin.api.Metainfo;
import org.backmeup.plugin.api.MetainfoContainer;
import org.backmeup.plugin.api.connectors.Datasource;
import org.backmeup.plugin.api.connectors.Progressable;
import org.backmeup.plugin.api.PluginContext;
import org.backmeup.plugin.api.Progressable;
import org.backmeup.plugin.api.storage.Storage;
import org.backmeup.plugin.api.storage.StorageException;

public class DummyDatasource implements Datasource, Validationable {
private static final String MIME_TYPE_TEXT_HTML = "text/html";
private static final String MIME_TYPE_TEXT_PLAIN = "text/plain";
private static final String OPTION_FAIL_VALIDATION = "fail validation";
private static final String OPTION_FAIL_HARD = "fail hard";

private static final List<String> BACKUP_OPTIONS = new ArrayList<>();

static {
BACKUP_OPTIONS.add("option1");
BACKUP_OPTIONS.add("option2");
BACKUP_OPTIONS.add("fail validation");
BACKUP_OPTIONS.add("fail hard");
BACKUP_OPTIONS.add(OPTION_FAIL_VALIDATION);
BACKUP_OPTIONS.add(OPTION_FAIL_HARD);
}

private InputStream stringToStream(String input) {
try {
InputStream is = new ByteArrayInputStream(input.getBytes("UTF-8"));
return is;
return new ByteArrayInputStream(input.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("UTF8 is not available?");
throw new IllegalArgumentException("UTF8 is not available?", e);
}
}

Expand All @@ -52,14 +57,14 @@ private Metainfo create(String id, String type, String destination) {
}

@Override
public void downloadAll(Map<String, String> accessData, Map<String, String> properties, List<String> options, Storage storage, Progressable progressor) throws StorageException {
public void downloadAll(PluginProfileDTO pluginProfile, PluginContext context, Storage storage, Progressable progressor) throws StorageException {
MetainfoContainer cont = new MetainfoContainer();
cont.addMetainfo(create("1", "text/plain", "/plain.txt"));
cont.addMetainfo(create("1", MIME_TYPE_TEXT_PLAIN, "/plain.txt"));
InputStream is = stringToStream("This is an important text file.\nPlease create a backup with this file");
storage.addFile(is, "/plain.txt", cont);

cont = new MetainfoContainer();
cont.addMetainfo(create("2", "text/html", "/html.txt"));
cont.addMetainfo(create("2", MIME_TYPE_TEXT_HTML, "/html.txt"));
is = stringToStream("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
+ "http://www.w3.org/TR/html4/strict.dtd\">"
+ "<html>"
Expand All @@ -78,7 +83,7 @@ public boolean hasRequiredProperties() {

@Override
public List<RequiredInputField> getRequiredProperties() {
return null;
return new ArrayList<>();
}

@Override
Expand All @@ -104,10 +109,10 @@ public ValidationNotes validateOptions(List<String> options) {
notes.addValidationEntry(ValidationExceptionType.ConfigException, DummyDescriptor.DUMMY_ID, "Option \""+option+"\" not available");
}
}
if (options.contains("fail validation")) {
if (options.contains(OPTION_FAIL_VALIDATION)) {
notes.addValidationEntry(ValidationExceptionType.ConfigException, DummyDescriptor.DUMMY_ID, "Option fail selected -> failing");
}
if (options.contains("fail hard")) {
if (options.contains(OPTION_FAIL_HARD)) {
throw new PluginException(DummyDescriptor.DUMMY_ID, "forced to fail hard!");
}
return notes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.HashMap;
import java.util.Map;

import org.backmeup.plugin.api.BaseSourceSinkDescribable;
import org.backmeup.plugin.api.Metadata;
import org.backmeup.plugin.api.connectors.BaseSourceSinkDescribable;

public class DummyDescriptor extends BaseSourceSinkDescribable {

Expand Down
16 changes: 16 additions & 0 deletions backmeup-facebook-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target/
target/*
bin/
bin/*
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
properties.xml
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.classpath
.project
.settings
.settings/*
27 changes: 27 additions & 0 deletions backmeup-facebook-plugin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2015, RStoeckl
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of themis-fb nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 268d1fa

Please sign in to comment.