Skip to content

Commit

Permalink
New rc version
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Feb 10, 2025
1 parent f1ad4b4 commit eadffee
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 88 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=cz.incad.kramerius
version=7.0.40-rc5
version=7.0.40-rc6
#version=7.0.40-devmerge
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -64,8 +80,17 @@ public static enum TypeOfReharvset {
private String podname;

private List<String> 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;
Expand All @@ -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;
Expand All @@ -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<String> getLibraries() {
return libraries;
}

public void setLibraries(List<String> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReharvestItem> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> 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<String> values
* = headers.get(key); values.stream().forEach(val -> { respEntity.header(key,
* val); }); });
*/
/*
* Disable header forward headers.keySet().forEach(key -> { List<String> 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();
}
}

Expand Down Expand Up @@ -237,7 +242,7 @@ public boolean acceptElement(Element element) {

Map<String, JSONObject> 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();
Expand Down
Loading

0 comments on commit eadffee

Please sign in to comment.