diff --git a/gradle.properties b/gradle.properties index 003fda4e8..acaee5e45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=cz.incad.kramerius -version=7.0.40-rc5 +version=7.0.40-rc6 #version=7.0.40-devmerge diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/ItemsResource.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/ItemsResource.java index 9d599a45c..4501d4075 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/ItemsResource.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/ItemsResource.java @@ -266,7 +266,7 @@ public Response introspectPidInInstances(@PathParam("pid") String pid) { throw new ForbiddenException("user '%s' is not allowed to do this (missing action '%s')", user, SecuredActions.A_ADMIN_READ.name()); //403 } try { - JSONObject obj = IntrospectUtils.introspectSolr(this.client, this.libraries, pid); + JSONObject obj = IntrospectUtils.introspectSolr(this.client, this.libraries, pid, true); return Response.ok(obj.toString()).build(); } catch (UnsupportedEncodingException | JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestItem.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestItem.java index ed10d53f7..4171f5f65 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestItem.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestItem.java @@ -14,23 +14,41 @@ import cz.incad.kramerius.utils.StringUtils; -/** - * Represents new Reharvest item - * @author happy +/** + * Represents an item that requires reharvesting in the digital library system. + * This class stores metadata about a document that should be updated due to various reasons + * such as outdated content, deletion, or conflicts. + * It allows conversion between object representation and JSON format. + * + * @author Pavel Šťastný */ public class ReharvestItem { - + + /** + * Enumeration of reharvest operation types. + * Defines the scope of reharvesting such as entire document, children, or specific entities. + */ public static enum TypeOfReharvset { - - root, // kompletni reharvest celeho titulu - children, // reharvest titulu a potomku - - new_children, // dilo v cdk smazano a je potreba stahnout z krameriu informace o detech a titulu a pak pomoci own_pid_path - new_root, // dilo je v cdk smazano a je potreba stahnot z krameriu informace o korenovem dile - + + /** Complete reharvest of the entire title */ + root, + + /** Reharvest of the title and its children */ + children, + + /** The item was removed from CDK, reharvest its children */ + new_children, + + /** The root item was removed from CDK, requiring reharvest */ + new_root, + + /** Reharvest only a specific PID */ only_pid, // pouze jeden pid - + + /** Delete a single PID */ delete_pid, + + /** Delete the entire document tree */ delete_tree; } @@ -49,11 +67,9 @@ public static enum TypeOfReharvset { public static final String LIBRARIES_KEYWORD = "libraries"; public static final String ERROR_MESSAGE_KEYWORD="error"; - // unique identifier private String id; private String name; private String state; - //private String type; private String pid; private String rootPid; private String ownPidPath; @@ -64,8 +80,17 @@ public static enum TypeOfReharvset { private String podname; private List libraries = new ArrayList<>(); - - + + + /** + * Constructs a new ReharvestItem. + * + * @param id Unique identifier. + * @param name Name of the document. + * @param state Current state of the document. + * @param pid Persistent identifier. + * @param ownPidPath Path to the document within the system. + */ public ReharvestItem(String id, String name, String state, String pid, String ownPidPath) { super(); this.id = id; @@ -75,6 +100,11 @@ public ReharvestItem(String id, String name, String state, String pid, String ow this.ownPidPath = ownPidPath; } + /** + * Constructs a ReharvestItem with an ID only. + * + * @param id Unique identifier. + */ public ReharvestItem(String id) { super(); this.id = id; @@ -84,83 +114,67 @@ public ReharvestItem(String id) { public String getId() { return id; } - public String getName() { return name; } public void setName(String name) { this.name = name; } - public String getState() { return state; } - public void setState(String state) { this.state = state; } - public String getPid() { return this.pid; } - - public void setPid(String pid) { this.pid = pid; } - public List getLibraries() { return libraries; } - public void setLibraries(List libraries) { this.libraries = libraries; - } public Instant getTimestamp() { return timestamp; } - public void setTimestamp(Instant timestamp) { this.timestamp = timestamp; } - - public void setPodname(String podname) { this.podname = podname; } - public String getPodname() { return podname; } - public String getOwnPidPath() { return ownPidPath; } - public void setOwnPidPath(String ownPidPath) { this.ownPidPath = ownPidPath; } - public TypeOfReharvset getTypeOfReharvest() { return typeOfReharvest; } - - public void setTypeOfReharvest(TypeOfReharvset typeOfReharvest) { this.typeOfReharvest = typeOfReharvest; } - - public String getRootPid() { return rootPid; } - public void setRootPid(String rootPid) { this.rootPid = rootPid; } - - + + + /** + * Converts the ReharvestItem into a JSON representation. + * + * @return JSONObject containing the item's properties. + */ public JSONObject toJSON() { JSONObject obj = new JSONObject(); obj.put(ID_KEYWORD, this.id); @@ -198,7 +212,14 @@ public JSONObject toJSON() { return obj; } - + + /** + * Creates a ReharvestItem from a JSON object. + * + * @param json The JSONObject containing item data. + * @return A new ReharvestItem object populated from JSON data. + * @throws ParseException If parsing timestamp fails. + */ public static ReharvestItem fromJSON(JSONObject json) throws ParseException { String id = json.getString(ID_KEYWORD); String name= json.getString(NAME_KEYWORD); @@ -238,7 +259,6 @@ public static ReharvestItem fromJSON(JSONObject json) throws ParseException { for (int i = 0; i < libsArray.length(); i++) { libs.add(libsArray.getString(i));} item.setLibraries(libs); } - return item; } } diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestManager.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestManager.java index 851d4a333..e9ccafbc7 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestManager.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/admin/v70/reharvest/ReharvestManager.java @@ -6,19 +6,66 @@ import org.json.JSONException; +/** + * Interface for managing reharvest operations in the digital library system. + * Provides methods to register, update, retrieve, and deregister reharvest items. + */ public interface ReharvestManager { + /** + * Registers a new reharvest item. + * + * @param item The ReharvestItem to be registered. + * @throws AlreadyRegistedPidsException If the PID is already registered. + */ public void register(ReharvestItem item) throws AlreadyRegistedPidsException; - + + /** + * Updates an existing reharvest item. + * + * @param item The ReharvestItem with updated data. + * @return The updated ReharvestItem. + * @throws UnsupportedEncodingException If encoding issues occur. + * @throws JSONException If JSON processing fails. + * @throws ParseException If date parsing fails. + */ public ReharvestItem update(ReharvestItem item) throws UnsupportedEncodingException, JSONException, ParseException; - + + /** + * Retrieves a list of all reharvest items. + * + * @return A list of ReharvestItem objects. + */ public List getItems(); - + + /** + * Retrieves the highest-priority reharvest item with a given status. + * + * @param status The status of the item to retrieve. + * @return The top-priority ReharvestItem with the specified status. + */ public ReharvestItem getTopItem(String status); + /** + * Retrieves a reharvest item by its unique identifier. + * + * @param id The ID of the item. + * @return The corresponding ReharvestItem. + */ public ReharvestItem getItemById(String id); + /** + * Retrieves an open reharvest item by its PID. + * + * @param pid The PID of the item. + * @return The open ReharvestItem associated with the given PID. + */ public ReharvestItem getOpenItemByPid(String pid); - + + /** + * Deregisters a reharvest item by its ID. + * + * @param id The ID of the item to be removed. + */ public void deregister(String id); } diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/ProxyHandlerSupport.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/ProxyHandlerSupport.java index 2ec23e587..702e8d2ef 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/ProxyHandlerSupport.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/ProxyHandlerSupport.java @@ -135,45 +135,50 @@ public Response buildForwardResponseGET(String url, String pid, boolean deleteTr public Response buildForwardResponseGET(String url, String mimetype, String pid, boolean deleteTrigger, boolean shibHeaders) throws ProxyHandlerException { WebResource.Builder b = buidForwardResponse(url, shibHeaders); - ClientResponse response = b.get(ClientResponse.class); - LOGGER.info("Status code response "+response.getStatus() + ",Mimetype "+mimetype+", pid "+pid+", deleteTrigger "+deleteTrigger+", shibHeaders "+shibHeaders); - if (response.getStatus() == 200) { - String responseMimeType = response.getType().toString(); - InputStream is = response.getEntityInputStream(); - MultivaluedMap headers = response.getHeaders(); - - StreamingOutput stream = new StreamingOutput() { - public void write(OutputStream output) throws IOException, WebApplicationException { - try { - IOUtils.copy(is, output); - } catch (Exception e) { - throw new WebApplicationException(e); + ClientResponse response =null; + try { + response = b.get(ClientResponse.class); + LOGGER.info("Status code response "+response.getStatus() + ",Mimetype "+mimetype+", pid "+pid+", deleteTrigger "+deleteTrigger+", shibHeaders "+shibHeaders); + if (response.getStatus() == 200) { + String responseMimeType = response.getType().toString(); + InputStream is = response.getEntityInputStream(); + MultivaluedMap headers = response.getHeaders(); + + StreamingOutput stream = new StreamingOutput() { + public void write(OutputStream output) throws IOException, WebApplicationException { + try { + IOUtils.copy(is, output); + } catch (Exception e) { + throw new WebApplicationException(e); + } } + }; + ResponseBuilder respEntity = null; + if (mimetype != null) { + respEntity = Response.status(200).entity(stream).type(mimetype); + } else if (responseMimeType != null) { + respEntity = Response.status(200).entity(stream).type(responseMimeType); + } else { + respEntity = Response.status(200).entity(stream); } - }; - ResponseBuilder respEntity = null; - if (mimetype != null) { - respEntity = Response.status(200).entity(stream).type(mimetype); - } else if (responseMimeType != null) { - respEntity = Response.status(200).entity(stream).type(responseMimeType); - } else { - respEntity = Response.status(200).entity(stream); - } - /* - * Disable header forward headers.keySet().forEach(key -> { List values - * = headers.get(key); values.stream().forEach(val -> { respEntity.header(key, - * val); }); }); - */ + /* + * Disable header forward headers.keySet().forEach(key -> { List values + * = headers.get(key); values.stream().forEach(val -> { respEntity.header(key, + * val); }); }); + */ - return respEntity.build(); - } else { - // event for reharvest - if (response.getStatus() == 404) { - if (deleteTrigger) - deleteTriggeToReharvest(pid); + return respEntity.build(); + } else { + // event for reharvest + if (response.getStatus() == 404) { + if (deleteTrigger) + deleteTriggeToReharvest(pid); + } + return Response.status(response.getStatus()).build(); } - return Response.status(response.getStatus()).build(); + } finally { + if (response != null) response.close(); } } @@ -237,7 +242,7 @@ public boolean acceptElement(Element element) { Map map = new HashMap<>(); - JSONObject jsonResult = IntrospectUtils.introspectSolr(this.client, this.instances, ownParentPidText); + JSONObject jsonResult = IntrospectUtils.introspectSolr(this.client, this.instances, ownParentPidText,false); Set keys = jsonResult.keySet(); for (Object keyObj : keys) { String key = keyObj.toString(); diff --git a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/utils/IntrospectUtils.java b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/utils/IntrospectUtils.java index 8fa31b4dd..7b06ba839 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/utils/IntrospectUtils.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/apiNew/client/v70/redirection/utils/IntrospectUtils.java @@ -60,13 +60,15 @@ public static Pair, List> introspectPid(Client client, Inst } /** introspect utils */ - public static JSONObject introspectSolr(Client client, Instances libraries, String pid) throws UnsupportedEncodingException { + public static JSONObject introspectSolr(Client client, Instances libraries, String pid, boolean cdkInclude) throws UnsupportedEncodingException { JSONObject obj = new JSONObject(); /** cdk request */ - String solrSearchHost = KConfiguration.getInstance().getSolrSearchHost(); - String response = ChannelUtils.solrChannelPidExistence(client, null, solrSearchHost, "v7", pid); - obj.put("_cdk_", new JSONObject(response)); + if (cdkInclude) { + String solrSearchHost = KConfiguration.getInstance().getSolrSearchHost(); + String response = ChannelUtils.solrChannelPidExistence(client, null, solrSearchHost, "v7", pid); + obj.put("_cdk_", new JSONObject(response)); + } /** instances request */ diff --git a/shared/common/build.gradle b/shared/common/build.gradle index 410ed7db6..16dcabf64 100644 --- a/shared/common/build.gradle +++ b/shared/common/build.gradle @@ -64,13 +64,15 @@ dependencies { api "com.sun.jersey:jersey-server:${jerseyversion}" api "com.sun.jersey:jersey-servlet:${jerseyversion}" - api "com.sun.jersey:jersey-client:${jerseyversion}" api "com.sun.jersey:jersey-json:${jerseyversion}" api 'com.sun.jersey.contribs:jersey-multipart:1.19.4' - api "com.sun.jersey.contribs:jersey-apache-client:${jerseyversion}" api "com.sun.jersey.contribs:jersey-guice:${jerseyversion}" + api "com.sun.jersey:jersey-client:${jerseyversion}" + api "com.sun.jersey.contribs:jersey-apache-client:${jerseyversion}" + + // for audio support api 'org.ehcache:ehcache:3.3.0' //api 'org.apache.httpcomponents:httpclient:4.3.2'