Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Deposit application running against f4 #538

Merged
merged 17 commits into from Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2b94f56
Added new context files to bring the deposit service online with fcre…
bbpennel Oct 27, 2016
49705ab
Added ContentRootObject for base object in the content tree. Added l…
bbpennel Nov 2, 2016
efefb61
Added repository initializer which sets up base objects for the repo.…
bbpennel Nov 2, 2016
07950bc
Added new ingest jobs into pipeline
bbpennel Nov 2, 2016
e4229bd
Fixed bug with FilePremisLogger where getEvents results would not inc…
bbpennel Nov 7, 2016
0238789
Added missing constructors to IngestDepositRecordJob and fixed log st…
bbpennel Nov 7, 2016
f82b1b1
Forcing fedora base to end with a /, parsing etags
bbpennel Nov 7, 2016
7f480b6
Added isUnmodified helper method to repository objects so that subcla…
bbpennel Nov 10, 2016
bd255d7
Added missing constructors for file availability job
bbpennel Nov 10, 2016
2715a19
Added main log4j file for deposit app and turned up test logging level
bbpennel Nov 10, 2016
a00df3e
Added logging to ingest content job to indicate progress. Fixed retr…
bbpennel Nov 10, 2016
0bae7d8
Added staging policy manager to spring context and injecting into ing…
bbpennel Nov 10, 2016
4ffacee
Updated test staging configuration for new reduced structure and fixe…
bbpennel Nov 10, 2016
168a482
Fixed typo in failure message
bbpennel Nov 16, 2016
905e468
Removed fcrepo3 context file for deposit app and renamed fcrepo4 to b…
bbpennel Nov 17, 2016
be927d3
Fixed comments and return on content root creation method
bbpennel Nov 17, 2016
0aac666
Added missing headers for Repo init IT
bbpennel Nov 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion deposit/src/main/resources/fcrepo-clients-context.xml
Expand Up @@ -17,7 +17,7 @@

<bean id="serverAddress" class="java.lang.String">
<constructor-arg
value="${fedora.protocol:https}://${fedora.host:localhost}:${fedora.port:443}/${fedora.context:fedora}" />
value="${fedora.protocol:https}://${fedora.host:localhost}:${fedora.port:443}/${fedora.context:fcrepo}" />
</bean>

<bean id="fcrepoClient" class="edu.unc.lib.dl.fcrepo4.FcrepoClientFactory" factory-method="makeClient">
Expand Down Expand Up @@ -52,4 +52,11 @@
</list>
</property>
</bean>

<bean id="repositoryInitializer" class="edu.unc.lib.dl.fcrepo4.RepositoryInitializer"
init-method="initializeRepository">
<property name="fcrepoClient" ref="fcrepoClient" />
<property name="repository" ref="repository" />
<property name="objFactory" ref="repositoryObjectFactory" />
</bean>
</beans>
@@ -0,0 +1,131 @@
/**
* Copyright 2016 The University of North Carolina at Chapel Hill
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.unc.lib.dl.fcrepo4;

import java.io.IOException;
import java.net.URI;

import org.apache.http.HttpStatus;
import org.fcrepo.client.FcrepoClient;
import org.fcrepo.client.FcrepoOperationFailedException;
import org.fcrepo.client.FcrepoResponse;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.DC;

import edu.unc.lib.dl.fedora.FedoraException;
import edu.unc.lib.dl.util.URIUtil;

/**
* Initializes the structure of the repository
*
* @author bbpennel
*
*/
public class RepositoryInitializer {

private Repository repository;

private RepositoryObjectFactory objFactory;

private FcrepoClient fcrepoClient;

public RepositoryInitializer() {
}

/**
* Initializes objects required for the base functionality of the repository
*/
public void initializeRepository() {
// Initialize the content base container
URI contentUri = createContainer(RepositoryPathConstants.CONTENT_BASE,
"Content Tree");

// Add the content tree root object
createContentRoot(contentUri);

// Initialize the path where deposit records are stored
createContainer(RepositoryPathConstants.DEPOSIT_RECORD_BASE,
"Deposit Records");
}

private URI createContainer(String id, String title) {
String containerString = URIUtil.join(repository.getFedoraBase(), id);
URI containerUri = URI.create(containerString);

// Abort initialization of already present container
if (objectExists(containerUri)) {
return containerUri;
}

Model model = ModelFactory.createDefaultModel();
Resource resc = model.createResource(containerString);
resc.addProperty(DC.title, title);

objFactory.createObject(containerUri, model);

return containerUri;
}

private URI createContentRoot(URI contentUri) {
String contentRootString = URIUtil.join(
contentUri, RepositoryPathConstants.CONTENT_ROOT_ID);
URI contentRootUri = URI.create(contentRootString);

// Don't initialize the object if it is already present.
if (objectExists(contentRootUri)) {
return contentUri;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return contentRootUri?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, it totally should

}

Model model = ModelFactory.createDefaultModel();
Resource resc = model.createResource(contentRootString);
resc.addProperty(DC.title, "Content Collections Root");


objFactory.createContentRootObject(contentRootUri, model);

return contentRootUri;
}

private boolean objectExists(URI uri) {
try (FcrepoResponse response = fcrepoClient.head(uri)
.perform()) {
return true;
} catch (IOException e) {
throw new FedoraException("Failed to close HEAD response for " + uri, e);
} catch (FcrepoOperationFailedException e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
return false;
}
throw new FedoraException("Failed to check on object " + uri
+ " during initialization", e);
}
}

public void setRepository(Repository repository) {
this.repository = repository;
}

public void setObjFactory(RepositoryObjectFactory objFactory) {
this.objFactory = objFactory;
}

public void setFcrepoClient(FcrepoClient fcrepoClient) {
this.fcrepoClient = fcrepoClient;
}
}
Expand Up @@ -58,7 +58,11 @@ protected URI createBaseContainer(String name) throws IOException, FcrepoOperati
* @throws IOException
*/
protected void assertObjectExists(PID pid) throws IOException, FcrepoOperationFailedException {
try (FcrepoResponse response = client.head(pid.getRepositoryUri()).perform()) {
assertObjectExists(pid.getRepositoryUri());
}

protected void assertObjectExists(URI uri) throws IOException, FcrepoOperationFailedException {
try (FcrepoResponse response = client.head(uri).perform()) {
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
}
Expand Down
@@ -0,0 +1,107 @@
package edu.unc.lib.dl.fcrepo4;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.net.URI;

import org.apache.http.HttpStatus;
import org.fcrepo.client.FcrepoResponse;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;

import edu.unc.lib.dl.rdf.Cdr;
import edu.unc.lib.dl.util.URIUtil;

public class RepositoryInitializerIT extends AbstractFedoraIT {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the IT stand for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Integration Test"


private RepositoryInitializer repoInitializer;

@Autowired
private Repository repository;

@Autowired
private RepositoryObjectFactory objFactory;

@Before
public void init() {
repoInitializer = new RepositoryInitializer();
repoInitializer.setObjFactory(objFactory);
repoInitializer.setRepository(repository);
repoInitializer.setFcrepoClient(client);
}

/**
* Ensure that expected objects were initialized
*
* @throws Exception
*/
@Test
public void fullInitializationTest() throws Exception {
repoInitializer.initializeRepository();

URI contentContainerUri = getContainerUri(RepositoryPathConstants.CONTENT_BASE);
assertObjectExists(contentContainerUri);

String contentRootString = URIUtil.join(
contentContainerUri, RepositoryPathConstants.CONTENT_ROOT_ID);
URI contentRootUri = URI.create(contentRootString);
assertObjectExists(contentRootUri);
Model crModel = repository.getObjectModel(contentRootUri);
Resource crResc = crModel.getResource(contentRootUri.toString());
assertTrue(crResc.hasProperty(RDF.type, Cdr.ContentRoot));

URI depositContainerUri = getContainerUri(RepositoryPathConstants.DEPOSIT_RECORD_BASE);
assertObjectExists(depositContainerUri);
}

/**
* Show that additional initialization calls after the first do no cause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...not cause...

* objects to be modified or recreated
*
* @throws Exception
*/
@Test
public void multipleInitializeTest() throws Exception {
repoInitializer.initializeRepository();

URI contentContainerUri = getContainerUri(RepositoryPathConstants.CONTENT_BASE);
String contentContainerEtag = getEtag(contentContainerUri);

String contentRootString = URIUtil.join(
contentContainerUri, RepositoryPathConstants.CONTENT_ROOT_ID);
URI contentRootUri = URI.create(contentRootString);
String contentRootEtag = getEtag(contentRootUri);

URI depositContainerUri = getContainerUri(RepositoryPathConstants.DEPOSIT_RECORD_BASE);
String depositContainerEtag = getEtag(depositContainerUri);

repoInitializer.initializeRepository();

assertEquals("Content Container object changed after second initialization",
contentContainerEtag, getEtag(contentContainerUri));
assertEquals("Content Root object changed after second initialization",
contentRootEtag, getEtag(contentRootUri));
assertEquals("Deposit Container object changed after second initialization",
depositContainerEtag, getEtag(depositContainerUri));
}

private String getEtag(URI uri) throws Exception {
try (FcrepoResponse response = client.head(uri).perform()) {
assertEquals(HttpStatus.SC_OK, response.getStatusCode());

String etag = response.getHeaderValue("ETag");
return etag.substring(1, etag.length() - 1);
}
}

private URI getContainerUri(String id) {
String containerString = URIUtil.join(repository.getFedoraBase(), id);
return URI.create(containerString);
}
}
Expand Up @@ -8,13 +8,10 @@

<bean id="serverAddress" class="java.lang.String">
<constructor-arg
value="http://localhost:${systemProperties['fcrepo.dynamic.test.port']:8080}/rest/" />
value="http://localhost:${systemProperties['fcrepo.dynamic.test.port']:48085}/rest/" />
</bean>

<bean id="fcrepoClientBuilder" class="org.fcrepo.client.FcrepoClient" factory-method="client">
</bean>

<bean id="fcrepoClient" factory-method="build" factory-bean="fcrepoClientBuilder">
<bean id="fcrepoClient" class="edu.unc.lib.dl.fcrepo4.FcrepoClientFactory" factory-method="makeClient">
</bean>

<bean id="ldpContainerFactory" class="edu.unc.lib.dl.fcrepo4.LdpContainerFactory">
Expand Down
Expand Up @@ -14,7 +14,7 @@

<bean id="containerWrapper" class="org.fcrepo.http.commons.test.util.ContainerWrapper"
init-method="start" destroy-method="stop">
<property name="port" value="${fcrepo.dynamic.test.port:8080}" />
<property name="port" value="${fcrepo.dynamic.test.port:48085}" />
<property name="configLocation" value="classpath:web.xml" />
</bean>

Expand Down