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

Bxc 4427 view settings #1677

Merged
merged 15 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading