Skip to content

Commit

Permalink
Bxc 4427 view settings (#1677)
Browse files Browse the repository at this point in the history
* Removing unused performance visualizations (#1666)

* Fix display of exhibits in the UI (#1665)

* Fix display of exhibits in the UI.

* Fix issue with multiple exhibits not being semicolon separated, and add tests

* Move exhibits below finding aid ino. Add a space when separating exhibit links

* Bxc 4416 cleanup temp files (#1667)

* BXC-4416 clean up temporary files

* Capture the email attachment when sendEmail is called for testing purposes

* BXC-4416 fix up tests

---------

Co-authored-by: Sharon Luong <[email protected]>
Co-authored-by: Ben Pennell <[email protected]>

* Address codeclimate issues

* BXC-4427 add initial files for setting view behavior

* Always reload metadata (#1669)

* update exhibit field label (#1673)

* BXC-4427 get request object and helper started

* BXC-4427 initial files and processor test

* BXC-4427 start on router test

* BXC-4427 making tests pass

* BXC-4427 rename view behavior classes to view settings for more flexibility

* BXC-4427 update javadoc to new class names

---------

Co-authored-by: Dean Farrell <[email protected]>
Co-authored-by: Sharon Luong <[email protected]>
Co-authored-by: Ben Pennell <[email protected]>
Co-authored-by: Ben Pennell <[email protected]>
Co-authored-by: Anna Goslen <[email protected]>
  • Loading branch information
6 people authored Feb 15, 2024
1 parent 1db22b8 commit dbe2911
Show file tree
Hide file tree
Showing 34 changed files with 509 additions and 11,421 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package edu.unc.lib.boxc.model.api.rdf;

import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;

import static org.apache.jena.rdf.model.ResourceFactory.createProperty;
import static org.apache.jena.rdf.model.ResourceFactory.createResource;

/**
* @author snluong
*/
public class CdrView {
private CdrView() {
}

/** The namespace of the vocabulary as a string */
public static final String NS = "http://cdr.unc.edu/definitions/view#";

/** The namespace of the vocabulary as a string
* @see #NS */
public static String getURI() {
return NS; }

/** The namespace of the vocabulary as a resource */
public static final Resource NAMESPACE = createResource( NS );

/** Used to define the IIIFv3 view "behavior" property for works.
* Valid values: https://iiif.io/api/presentation/3.0/#behavior */
public static final Property viewBehavior = createProperty(
"http://cdr.unc.edu/definitions/view#behavior");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package edu.unc.lib.boxc.operations.jms.viewSettings;


import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import edu.unc.lib.boxc.auth.api.models.AgentPrincipals;
import edu.unc.lib.boxc.auth.fcrepo.models.AgentPrincipalsImpl;

/**
* Request object for updating the view settings of the UV
* @author sharonluong
*/
public class ViewSettingRequest {
private String objectPidString;
private ViewBehavior viewBehavior;

@JsonDeserialize(as = AgentPrincipalsImpl.class)
private AgentPrincipals agent;
public enum ViewBehavior {
INDIVIDUALS,
PAGED,
CONTINUOUS
}

public String getObjectPidString() {
return objectPidString;
}

public void setObjectPidString(String objectPidString) {
this.objectPidString = objectPidString;
}

public ViewBehavior getViewBehavior() {
return viewBehavior;
}

public void setViewBehavior(ViewBehavior viewBehavior) {
this.viewBehavior = viewBehavior;
}

public AgentPrincipals getAgent() {
return agent;
}

public void setAgent(AgentPrincipals agent) {
this.agent = agent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.unc.lib.boxc.operations.jms.viewSettings;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;

import java.io.IOException;

/**
* Helper methods for serializing and deserializing view setting requests
* @author snluong
*/
public class ViewSettingRequestSerializationHelper {
private static final ObjectWriter REQUEST_WRITER;
private static final ObjectReader REQUEST_READER;

static {
ObjectMapper mapper = new ObjectMapper();
REQUEST_WRITER = mapper.writerFor(ViewSettingRequest.class);
REQUEST_READER = mapper.readerFor(ViewSettingRequest.class);
}

private ViewSettingRequestSerializationHelper() {
}

public static String toJson(ViewSettingRequest request) throws JsonProcessingException {
return REQUEST_WRITER.writeValueAsString(request);
}

public static ViewSettingRequest toRequest(String json) throws IOException {
return REQUEST_READER.readValue(json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -150,7 +151,10 @@ private void performExport(ExportXMLRequest request, long startTime) throws IOEx
xfop.write(("</" + BULK_MD_TAG + ">").getBytes(UTF_8));
}

sendEmail(zipit(mdExportFile, filename), request, filename, pageStart, pageEnd, totalPids);
File zipFile = zipit(mdExportFile, filename);
sendEmail(zipFile, request, filename, pageStart, pageEnd, totalPids);
cleanupTempFiles(zipFile, mdExportFile);

log.info("Completed exported objects {} through {} for user {} to {}",
pageStart, pageEnd, username, filename);
}
Expand Down Expand Up @@ -346,6 +350,11 @@ private File zipit(File mdExportFile, String filename) throws IOException {
return mdExportZip;
}

private void cleanupTempFiles(File zipFile, File xmlFile) throws IOException {
Files.delete(zipFile.toPath());
Files.delete(xmlFile.toPath());
}

private void sendEmail(File mdExportFile, ExportXMLRequest request, String filename,
int pageStart, int pageEnd, int totalPids) {
String emailBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.unc.lib.boxc.services.camel.viewSettings;

import edu.unc.lib.boxc.auth.api.Permission;
import edu.unc.lib.boxc.auth.api.services.AccessControlService;
import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader;
import edu.unc.lib.boxc.model.api.objects.WorkObject;
import edu.unc.lib.boxc.model.api.rdf.CdrView;
import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.operations.jms.viewSettings.ViewSettingRequestSerializationHelper;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

/**
* Processor for requests for updating the view settings for UV
*
* @author snluong
*/
public class ViewSettingRequestProcessor implements Processor {
private AccessControlService accessControlService;
private RepositoryObjectLoader repositoryObjectLoader;
private RepositoryObjectFactory repositoryObjectFactory;

@Override
public void process(Exchange exchange) throws Exception {
var in = exchange.getIn();
var request = ViewSettingRequestSerializationHelper.toRequest(in.getBody(String.class));
var agent = request.getAgent();
var pid = PIDs.get(request.getObjectPidString());

accessControlService.assertHasAccess("User does not have permission to update view behavior",
pid, agent.getPrincipals(), Permission.ingest);

var repositoryObject = repositoryObjectLoader.getRepositoryObject(pid);
var behavior = request.getViewBehavior();

if (repositoryObject instanceof WorkObject) {
if (behavior == null) {
repositoryObjectFactory.deleteProperty(repositoryObject, CdrView.viewBehavior);
} else {
repositoryObjectFactory.createExclusiveRelationship(repositoryObject, CdrView.viewBehavior, behavior);
}
}
// TODO BXC-4428 send message to update solr
}

public void setAccessControlService(AccessControlService accessControlService) {
this.accessControlService = accessControlService;
}

public void setRepositoryObjectLoader(RepositoryObjectLoader repositoryObjectLoader) {
this.repositoryObjectLoader = repositoryObjectLoader;
}

public void setRepositoryObjectFactory(RepositoryObjectFactory repositoryObjectFactory) {
this.repositoryObjectFactory = repositoryObjectFactory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.unc.lib.boxc.services.camel.viewSettings;

import org.apache.camel.BeanInject;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;

import static org.apache.camel.LoggingLevel.DEBUG;
import static org.slf4j.LoggerFactory.getLogger;

/**
* Router for processing requests to update view setting of UV
*
* @author snluong
*/
public class ViewSettingRouter extends RouteBuilder {
private static final Logger log = getLogger(ViewSettingRouter.class);

@BeanInject(value = "viewSettingRequestProcessor")
private ViewSettingRequestProcessor viewSettingRequestProcessor;

@Override
public void configure() throws Exception {
from("{{cdr.viewsetting.stream.camel}}")
.routeId("DcrViewSetting")
.log(DEBUG, log, "Received view setting request")
.bean(viewSettingRequestProcessor);
}
}
10 changes: 10 additions & 0 deletions services-camel-app/src/main/webapp/WEB-INF/service-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@
<property name="repositoryObjectFactory" ref="repositoryObjectFactory" />
</bean>

<bean id="viewBehaviorRequestProcessor" class="edu.unc.lib.boxc.services.camel.viewSettings.ViewSettingRequestProcessor">
<property name="accessControlService" ref="aclService" />
<property name="repositoryObjectLoader" ref="repositoryObjectLoader" />
<property name="repositoryObjectFactory" ref="repositoryObjectFactory" />
</bean>

<!-- Camel contexts -->

<camel:camelContext id="FcrepoTriplestoreIndexer">
Expand Down Expand Up @@ -567,4 +573,8 @@
<camel:camelContext id="CdrThumbnails">
<camel:package>edu.unc.lib.boxc.services.camel.thumbnails</camel:package>
</camel:camelContext>

<camel:camelContext id="CdrViews">
<camel:package>edu.unc.lib.boxc.services.camel.viewSettings</camel:package>
</camel:camelContext>
</beans>
Loading

0 comments on commit dbe2911

Please sign in to comment.