Skip to content

Commit

Permalink
Fixed #720
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.stastny committed Mar 31, 2020
1 parent 6849f40 commit 16838e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void logDnntAccess(String pid,
String remoteAddr,
String username,
String email,
List<String> dcAuthors,
ObjectPidsPath[] paths,
ObjectModelsPath[] mpaths) throws IOException {

Expand All @@ -60,6 +61,13 @@ public static void logDnntAccess(String pid,

jObject.put("date",timestamp);

if (!dcAuthors.isEmpty()) {
JSONArray authorsArray = new JSONArray();
for (int i=0,ll=dcAuthors.size();i<ll;i++) {
authorsArray.put(dcAuthors.get(i));
}
jObject.put("authors",authorsArray);
}

JSONArray pidsArray = new JSONArray();
for (int i = 0; i < paths.length; i++) {
Expand All @@ -72,7 +80,6 @@ public static void logDnntAccess(String pid,
modelsArray.put(pathToString(mpaths[i].getPathFromRootToLeaf()));
}
jObject.put("models_path",modelsArray);

if (paths.length > 0) {
String[] pathFromRootToLeaf = paths[0].getPathFromRootToLeaf();
if (pathFromRootToLeaf.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -125,12 +126,34 @@ public void reportAccess(final String pid, final String streamName) throws IOExc


Document solrDoc = this.solrAccess.getSolrDataDocument(pid);

String rootTitle = titleElement("str", "root_title", solrDoc);
String rootPid = titleElement("str", "root_pid", solrDoc);
String dctitle = titleElement("str", "dc.title", solrDoc);
//String dctitle = titleElement("str", "dc.title", solrDoc);
List<String> authors = new ArrayList<>();
if (rootPid != null) {
Document rootSolrDoc = this.solrAccess.getSolrDataDocument(rootPid);
Element array = XMLUtils.findElement(rootSolrDoc.getDocumentElement(), new XMLUtils.ElementsFilter() {
@Override
public boolean acceptElement(Element element) {
String nodeName = element.getNodeName();
String attr = element.getAttribute("name");
if (nodeName.equals("arr") && StringUtils.isAnyString(attr) && attr.equals("dc.creator"))
return true;
return false;
}
});
if (array != null) {
authors = XMLUtils.getElements(array).stream().map(it -> it.getTextContent()).filter(it -> it != null).map(String::trim).collect(Collectors.toList());
}
}



// REPORT DNNT
if (reportedAction.get() == null || reportedAction.get().equals(ReportedAction.READ)) {
reportDNNT(pid,rootTitle,dctitle, paths, mpaths, userProvider.get());
reportDNNT(pid,rootTitle,dctitle,authors, paths, mpaths, userProvider.get());
}


Expand Down Expand Up @@ -182,6 +205,7 @@ public void reportAccess(final String pid, final String streamName) throws IOExc
}
}


private String titleElement(String type, String attrVal, Document solrDoc) {
Element titleElm = XMLUtils.findElement(solrDoc.getDocumentElement(), new XMLUtils.ElementsFilter() {
@Override
Expand All @@ -195,7 +219,7 @@ public boolean acceptElement(Element element) {
return titleElm != null ? titleElm.getTextContent() : null;
}

private void reportDNNT(String pid, String rootTitle, String dcTitle, ObjectPidsPath[] paths, ObjectModelsPath[] mpaths, User user) throws IOException {
private void reportDNNT(String pid, String rootTitle, String dcTitle, List<String> dcAuthors, ObjectPidsPath[] paths, ObjectModelsPath[] mpaths, User user) throws IOException {
RightsReturnObject rightsReturnObject = CriteriaDNNTUtils.currentThreadReturnObject.get();
if (rightsReturnObject == null) return;
if (CriteriaDNNTUtils.checkContainsCriteriumReadDNNT(rightsReturnObject)) {
Expand All @@ -204,6 +228,7 @@ private void reportDNNT(String pid, String rootTitle, String dcTitle, ObjectPids
IPAddressUtils.getRemoteAddress(requestProvider.get(), KConfiguration.getInstance().getConfiguration()),
user!= null ? user.getLoginname() : null,
user != null ? user.getEmail(): null,
dcAuthors,
paths,
mpaths
);
Expand Down

0 comments on commit 16838e8

Please sign in to comment.