diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..91b25e7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.settings +.classpath +.project +.*.swp +workbench.xmi +target diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..d00707e3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: java +sudo: false +jdk: + - oraclejdk8 + +before_install: + - "echo $JAVA_OPTS" + - "export JAVA_OPTS=-Xmx512m" + +script: + - mvn install -B -V + - mvn javadoc:jar + - mvn javadoc:test-aggregate + +notifications: + irc: "irc.freenode.org#islandora" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..497d334d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,77 @@ +# Welcome! + +If you are reading this document then you are interested in contributing to the Islandora CLAW, and Salmon. All contributions are welcome: use-cases, documentation, code, patches, bug reports, feature requests, etc. You do not need to be a programmer to speak up! + +## Workflows + +The group meets each Wednesday at 1PM Eastern. Meeting notes and announcements are posted to the [Islandora community list](https://groups.google.com/forum/#!forum/islandora) and the [Islandora developers list](https://groups.google.com/forum/#!forum/islandora-dev). You can view meeting agendas, notes, and call-in information [here](https://github.com/Islandora-CLAW/CLAW/wiki#islandora-7x-2x-tech-calls). Anybody is welcome to join the calls, and add items to the agenda. + +### Use cases + +If you would like to submit a use case for the Islandora and Fedora integration project, please submit and issue [here](https://github.com/Islandora-CLAW/CLAW/issues/new) using the [Use Case template](https://github.com/Islandora/Islandora-Fedora4-Interest-Group/wiki/Use-Case-template), assign the "use case" label to the issue. + +### Documentation + +You can contribute documentation in two different ways. One way is to create an issue [here](https://github.com/Islandora-CLAW/CLAW/issues/new) assign the "documentation" label to the issue. Another way is to by pull request, same process as [Contribute Code](https://github.com/Islandora-CLAW/CLAW/blob/7.x-2.x/contributing.md#contribute-code). All documentation resides in [`docs`](https://github.com/Islandora-CLAW/CLAW/tree/7.x-2.x/docs). + + +### Request a new feature + +To request a new feature you should [open an issue](https://github.com/Islandora-CLAW/CLAW/issues/new) or create a [use case](https://github.com/Islandora-CLAW/CLAW/blob/7.x-2.x/CONTRIBUTING.md#use-cases) (see _use case_ section above), and summarize the desired functionality. Select the label "enhancement" if creating an issue on the project repo, and "use case" if creating a use case in the interest group repo. + +### Report a bug + +To report a bug you should [open an issue](https://github.com/Islandora-CLAW/CLAW/issues/new) that summarizes the bug. Set the label to "bug". + +In order to help us understand and fix the bug it would be great if you could provide us with: + +1. The steps to reproduce the bug. This includes information about e.g. the Islandora version you were using along with version of stack components. +2. The expected behavior. +3. The actual, incorrect behavior. + +Feel free to search the issue queue for existing issues (aka tickets) that already describe the problem; if there is such a ticket please add your information as a comment. + +**If you want to provide a pull along with your bug report:** + +That is great! In this case please send us a pull request as described in section _[Create a pull request](https://github.com/Islandora-CLAW/CLAW/blob/7.x-2.x/CONTRIBUTING.md#create-a-pull-request)_ below. + +### Contribute code + +Before you set out to contribute code you will need to have completed a [Contributor License Agreement](http://islandora.ca/sites/default/files/islandora_cla.pdf) or be covered by a [Corporate Contributor Licencse Agreement](http://islandora.ca/sites/default/files/islandora_ccla.pdf). The signed copy of the license agreement should be sent to + +_If you are interested in contributing code to Islandora but do not know where to begin:_ + +In this case you should [browse open issues](https://github.com/Islandora-CLAW/CLAW/issues), and or [use cases](https://github.com/Islandora/Islandora-Fedora4-Interest-Group/labels/use%20case). + +If you are contributing Drupal code, it must adhere to [Drupal Coding Standards](https://www.drupal.org/coding-standards); Travis CI will check for this on pull requests. + +Contributions to the Islandora codebase should be sent as GitHub pull requests. See section _Create a pull request_ below for details. If there is any problem with the pull request we can work through it using the commenting features of GitHub. + +* For _small patches_, feel free to submit pull requests directly for those patches. +* For _larger code contributions_, please use the following process. The idea behind this process is to prevent any wasted work and catch design issues early on. + + 1. [Open an issue](https://github.com/Islandora-CLAW/CLAW/issues) and assign it the label of "enhancement", if a similar issue does not exist already. If a similar issue does exist, then you may consider participating in the work on the existing issue. + 2. Comment on the issue with your plan for implementing the issue. Explain what pieces of the codebase you are going to touch and how everything is going to fit together. + 3. Islandora committers will work with you on the design to make sure you are on the right track. + 4. Implement your issue, create a pull request (see below), and iterate from there. + +### Create a pull request + +Take a look at [Creating a pull request](https://help.github.com/articles/creating-a-pull-request). In a nutshell you need to: + +1. [Fork](https://help.github.com/articles/fork-a-repo) the Islandora GitHub repository at [https://github.com/Islandora-CLAW/CLAW](https://github.com/Islandora-CLAW/CLAW) to your personal GitHub account. If you already have a fork of [https://github.com/Islandora/islandora](https://github.com/Islandora/islandora) Github will prevent you from creating a new fork; in such a case you can continue to use [https://github.com/Islandora/islandora](https://github.com/Islandora/islandora) to issue pull request, be cautious of which branches you work from though (you'll want to base your work off of 7.x-2.x). Also be cautious of which repository your issuing your Pull Request to (you'll want to issue your pull request to [https://github.com/Islandora-CLAW/CLAW](https://github.com/Islandora-CLAW/CLAW)). See [Fork a repo](https://help.github.com/articles/fork-a-repo) for detailed instructions. +2. Commit any changes to your fork. +3. Send a [pull request](https://help.github.com/articles/creating-a-pull-request) to the Islandora GitHub repository that you forked in step 1. If your pull request is related to an existing issue -- for instance, because you reported a [bug/issue](https://github.com/Islandora-CLAW/CLAW/issues) earlier -- prefix the title of your pull request with the corresponding issue number (e.g. `issue-123: ...`). Please also include a reference to the issue in the description of the pull. This can be done by using '#' plus the issue number like so '#123', also try to pick an appropriate name for the branch in which you're issuing the pull request from. + +You may want to read [Syncing a fork](https://help.github.com/articles/syncing-a-fork) for instructions on how to keep your fork up to date with the latest changes of the upstream (official) `islandora` repository. + +Please note that TravisCI will test for [PSR-2](http://www.php-fig.org/psr/psr-2/) compliance. You can verify coding standard compliance with [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer). + +**Note**: Due to differing interpretations of the PSR-2 coding standards do **not** use PHP [Coding Standards Fixer](http://cs.sensiolabs.org/). Coding Standards Fixer may make changes to your code that can cause it to fail our TravisCI tests. + +In addition, Islandora 7.x-2.x Committers will review contributions for [PSR-4 ](http://www.php-fig.org/psr/psr-4/) compliance. + +## License Agreements + +The Islandora Foundation requires that contributors complete a [Contributor License Agreement](http://islandora.ca/sites/default/files/islandora_cla.pdf) or be covered by a [Corporate Contributor Licencse Agreement](http://islandora.ca/sites/default/files/islandora_ccla.pdf). The signed copy of the license agreement should be sent to community@islandora.ca. This license is for your protection as a contributor as well as the protection of the Foundation and its users; it does not change your rights to use your own contributions for any other purpose. + diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/NOTICE b/NOTICE new file mode 100644 index 00000000..35678e5b --- /dev/null +++ b/NOTICE @@ -0,0 +1,2 @@ +Salmon +Copyright 2013-2016 Islandora Foundation diff --git a/README.md b/README.md new file mode 100644 index 00000000..3ffacc7d --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# ![Salmon](https://cloud.githubusercontent.com/assets/218561/18217846/143cd4c2-712d-11e6-8428-1b721f3ad164.png) Salmon +[![Build Status](https://travis-ci.org/Islandora-CLAW/Salmon.svg?branch=master)](https://travis-ci.org/Islandora-CLAW/Salmon) +[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md) +[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE) + +## Introduction + +Event driven middleware based on Apache Camel that synchronizes a Fedora 4 JCR with a Drupal CMS. + +## Requirements + +* Java 8 +* Maven 3 +* A servlet container + +## Compilation + +`mvn install` + +## Deployment + +After successful compilation, copy the resulting war from the target directory to the deployment directory of your servlet container. + +## Sponsors + +* UPEI +* discoverygarden inc. +* LYRASIS +* McMaster University +* University of Limerick +* York University +* University of Manitoba +* Simon Fraser University +* PALS +* American Philosophical Society +* common media inc. + +## Maintainers + +* [Nick Ruest](https://github.com/ruebot) +* [Daniel Lamb](https://github.com/dannylamb/) + +## Development + +If you would like to contribute, please get involved by attending our weekly [Tech Call](https://github.com/Islandora-CLAW/CLAW/wiki). We love to hear from you! + +If you would like to contribute code to the project, you need to be covered by an Islandora Foundation [Contributor License Agreement](http://islandora.ca/sites/default/files/islandora_cla.pdf) or [Corporate Contributor Licencse Agreement](http://islandora.ca/sites/default/files/islandora_ccla.pdf). Please see the [Contributors](http://islandora.ca/resources/contributors) pages on Islandora.ca for more information. + +## License + +MIT diff --git a/Salmon/pom.xml b/Salmon/pom.xml new file mode 100644 index 00000000..88337353 --- /dev/null +++ b/Salmon/pom.xml @@ -0,0 +1,248 @@ + + + + 4.0.0 + + + ca.islandora + islandora-parent + 0.0.2 + + + ca.islandora.sync + salmon-sync-gateway + bundle + + + Islandora Foundation + http://islandora.ca/ + + + Islandora CLAW Sync Gateway + + + ca.islandora.sync.islandora-sync-gateway + 2.15.1 + 1.7.12 + 1.2.17 + 4.4.0 + 0.0.2 + 2.4 + + + + + org.apache.camel + camel-core + + + org.apache.camel + camel-blueprint + + + org.apache.camel + camel-http + + + org.apache.camel + camel-script + + + org.fcrepo.camel + fcrepo-camel + + + ca.islandora.component + islandora-camel-component + ${project.version} + + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + org.apache.camel + camel-test-blueprint + + + + + + install + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.apache.maven.plugins + maven-resources-plugin + + + + + org.apache.felix + maven-bundle-plugin + + + + org.codehaus.mojo + build-helper-maven-plugin + + + package + + attach-artifact + + + + + src/main/cfg/ca.islandora.sync.cfg + cfg + configuration + + + + + + + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + true + + + + + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/content/repositories/releases + + true + + + false + + + + + + + dannylamb + Daniel Lamb + dlamb @ (domain of organization url) + Islandora Foundation + http://islandora.ca + + developer + + -4 + + + ruebot + Nick Ruest + ruestn @ (domain of organization url) + York University + http://yorku.ca/ + + developer + + -5 + + + + + scm:git:git@github.com:Islandora-CLAW/Salmon.git + scm:git:git@github.com:Islandora-CLAW/Salmon.git + https://github.com/islandora-claw/Alpaca + HEAD + + + + GitHub + https://github.com/Islandora-CLAW/CLAW/issues + + + + + MIT + https://opensource.org/licenses/MIT + Copyright (c) 2015 Islandora Foundation + + + + + + gh-pages + Deployment through GitHub's site deployment plugin + site/${project.version} + + + + + + islandora-dev + islandora-dev+subscribe@googlegroups.com + islandora-dev+unsubscribe@googlegroups.com + islandora-dev@googlegroups.com + https://groups.google.com/d/forum/islandora-dev + + + + diff --git a/Salmon/src/main/cfg/ca.islandora.sync.cfg b/Salmon/src/main/cfg/ca.islandora.sync.cfg new file mode 100644 index 00000000..c734f273 --- /dev/null +++ b/Salmon/src/main/cfg/ca.islandora.sync.cfg @@ -0,0 +1,7 @@ +islandora.drupal.baseurl = localhost/islandora +islandora.drupal.username = admin +islandora.drupal.password = islandora +islandora.fcrepo.baseurl = localhost:8080/fcrepo/rest +islandora.php.workingDir = /home/vagrant/islandora/camel/commands/bin +islandora.php.executable = islandora.php +islandora.triplestore.baseurl = localhost:8080/bigdata/namespace/kb/sparql diff --git a/Salmon/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/Salmon/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 00000000..8d675bbe --- /dev/null +++ b/Salmon/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Salmon/src/main/resources/OSGI-INF/blueprint/drupalAuthentication.xml b/Salmon/src/main/resources/OSGI-INF/blueprint/drupalAuthentication.xml new file mode 100644 index 00000000..96f37eeb --- /dev/null +++ b/Salmon/src/main/resources/OSGI-INF/blueprint/drupalAuthentication.xml @@ -0,0 +1,125 @@ + + + + + + + + Gets Drupal authentication information (cookie, token), and adds it as properties on the exchange + + + + + + + Attempts to get the Drupal session cookie from the cache, re-attempting login if it's not found + + CamelCacheGet + {{islandora.drupal.username}} + + + ${headers.CamelCacheElementWasFound} == ${null} + + + + ${bodyAs(String)} + + + + + + Attempts to get the Drupal X-CSRF token from the cache, re-attempting login if it's not found + + CamelCacheGet + {{islandora.drupal.username}} + + + ${headers.CamelCacheElementWasFound} == ${null} + + + + ${bodyAs(String)} + + + + + + Smartly logs into Drupal with error handling + + + + + org.apache.camel.component.http.HttpOperationFailedException + ${exception.statusCode} == 401 && ${exception.responseBody} == '["CSRF validation failed"]' + + + + + + + Logs into Drupal + + + POST + application/json + {"username": "{{islandora.drupal.username}}", "password" : "{{islandora.drupal.password}}"} + + ${bodyAs(String)} + + + + + + Extracts session cookie from login response + + ${property.authResponse} + $['session_name'] + $['sessid'] + ${property.sessionName}=${property.sessionId} + + + + + Adds the Drupal session cookie to the cache + + CamelCacheAdd + {{islandora.drupal.username}} + ${property.cookie} + + + + + Extracts X-CSRF token from login response + + ${property.authResponse} + $['token'] + + + + + Adds the Drupal X-CSRF token to the cache + + CamelCacheAdd + {{islandora.drupal.username}} + ${property.token} + + + + + Logs out of Drupal + + + POST + application/json + ${property.token} + ${property.cookie} + ${null} + + + + + + diff --git a/Salmon/src/main/resources/OSGI-INF/blueprint/eventGateway.xml b/Salmon/src/main/resources/OSGI-INF/blueprint/eventGateway.xml new file mode 100644 index 00000000..fffeea74 --- /dev/null +++ b/Salmon/src/main/resources/OSGI-INF/blueprint/eventGateway.xml @@ -0,0 +1,241 @@ + + + + + + + + Content based router for incoming Fedora events + + ${headers[org.fcrepo.jms.baseURL]} + ${headers[org.fcrepo.jms.identifier]} + + + ${headers[org.fcrepo.jms.eventType]} contains 'http://fedora.info/definitions/v4/repository#NODE_REMOVED' + + + + + + + + + + Event handler for node upsert events + + + + ${property.rdf} + $[0]['@type'] + + "http://www.w3.org/ns/ldp#NonRDFSource" in ${body} + + + + + + + + + + Event handler for node removed events + + + + + + + + + + + + ${property.node} == '[false]' + + + + + + + + + + + Gets RDF from Fedora + + + GET + ${property.CamelFcrepoBaseUrl} + ${property.CamelFcrepoIdentifier} + application/ld+json + + ${bodyAs(String)} + + + + Extracts a Drupal UUID from Fedora RDF + + ${property.rdf} + + $[0]['http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/uuid'][0]['@value'] + + java.lang.Exception + + + + + + + + Gets node JSON from Drupal + + + GET + application/json + ${property.token} + ${property.cookie} + ${null} + http:{{islandora.drupal.baseurl}}/node/${property.uuid} + ${bodyAs(String)} + + + + Creates a Drupal node using RDF + + + + {"rdf" : ${property.rdf}, "contentType" : "${property.contentType}", "uuid" : "${property.uuid}", "mappings" : ${property.mappings}} + + + + + Extracts an Islandora content type from RDF + + ${property.rdf} + + ${bodyAs(String)} + + + + Gets an RDF mapping from Drupal + + GET + application/json + ${property.token} + ${property.cookie} + ${null} + http:{{islandora.drupal.baseurl}}/rdf_mapping/node/${property.contentType} + ${bodyAs(String)} + + + + Updates a Drupal node using RDF + + {"node" : ${property.node}, "rdf" : ${property.rdf}} + + + + + PUTs a node using Drupal's services module + + + PUT + application/json + ${property.token} + ${property.cookie} + true + http:{{islandora.drupal.baseurl}}/node/${property.uuid} + + + + Deletes a node in Drupal using its Fedora URI + + + POST + application/json + ${property.token} + ${property.cookie} + true + {"fedoraUri": "${property.CamelFcrepoBaseUrl}${property.CamelFcrepoIdentifier}"} + + + + + + ${property.rdf} + + $[0]['http://fedora.info/definitions/v4/repository#hasParent'][0]['@id'] + + + + + + java.lang.Exception + + + + + + + + + ${null} + + GET + application/ld+json + + ${property.parentUri} + ${bodyAs(String)} + ${property.parentRdf} + $[0]['http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/uuid'][0]['@value'] + + + + Gets a binary from Fedora + + + ${null} + GET + ${property.CamelFcrepoBaseUrl}/${property.CamelFcrepoIdentifier} + ${body} + ${headers.Content-Length} + ${headers.Content-Type} + + + + Adds a binary from Fedora to Drupal as a thumbnail + + + ${property.binary} + + ${body} + { "uuid" : "${property.parentUuid}", "file" : "${property.b64file}", "mimetype" : "${property.mimetype}"} + POST + application/json + ${property.token} + ${property.cookie} + true + http:{{islandora.drupal.baseurl}}/tn + + + + Adds a binary from Fedora to Drupal as a medium size image + + + ${property.binary} + + ${body} + { "uuid" : "${property.parentUuid}", "file" : "${property.b64file}", "mimetype" : "${property.mimetype}"} + POST + application/json + ${property.token} + ${property.cookie} + true + http:{{islandora.drupal.baseurl}}/medium_size + + + + diff --git a/Salmon/src/main/resources/log4j.properties b/Salmon/src/main/resources/log4j.properties new file mode 100644 index 00000000..88663293 --- /dev/null +++ b/Salmon/src/main/resources/log4j.properties @@ -0,0 +1,18 @@ +# +# The logging properties used for testing +# +log4j.rootLogger=INFO, out + +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n +log4j.appender.file.file=target/camel-test.log