Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/clarin-dev' into clarin
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarko committed Jun 6, 2023
2 parents 8cf3758 + bbac9d1 commit 8a6ba5c
Show file tree
Hide file tree
Showing 26 changed files with 132,448 additions and 83,618 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package cz.cuni.mff.ufal.dspace.runnable;

import cz.cuni.mff.ufal.DSpaceApi;
import cz.cuni.mff.ufal.lindat.utilities.HibernateFunctionalityManager;
import cz.cuni.mff.ufal.lindat.utilities.hibernate.LicenseResourceMapping;
import cz.cuni.mff.ufal.lindat.utilities.interfaces.IFunctionalities;
import org.dspace.content.*;
import org.dspace.core.Constants;
import org.dspace.core.Context;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class CheckLicenses {
static private IFunctionalities f = DSpaceApi.getFunctionalityManager();
static private Context ctx = null;

public static void main(String[] args){
f.openSession();
try {
ctx = new Context();
ctx.turnOffAuthorisationSystem();
ItemIterator items = Item.findAll(ctx);
while (items.hasNext()) {
Item item = items.next();
checkMetadataAndDatabaseMatch(item);
}
checkUnexpectedAnonymousConfirmation();
ctx.restoreAuthSystemState();
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
f.closeSession();
if (ctx != null) {
ctx.abort();
}
}
}

private static void checkUnexpectedAnonymousConfirmation() throws SQLException {
HibernateFunctionalityManager hf = (HibernateFunctionalityManager)f;
List<Integer> bitstreamIdsOfAskOnlyOnceWhereConfirmedByAnonymous = hf.getBitstreamIdsOfAskOnlyOnceWhereConfirmedByAnonymous();

HashSet<Item> items = new HashSet<Item>();
for(int bitstream_id : bitstreamIdsOfAskOnlyOnceWhereConfirmedByAnonymous){
Bitstream b = Bitstream.find(ctx, bitstream_id);
if(b == null){
System.out.println("ERR: Bitstream " + bitstream_id + " not found");
}else{
DSpaceObject parentObject = b.getParentObject();
if(parentObject.getType() == Constants.ITEM) {
items.add((Item) parentObject);
}
}
}
for(Item i :items){
System.out.println("ERR: Item " + i.getID() + " has unexpected anonymous confirmation");
}
}

private static void checkMetadataAndDatabaseMatch(Item item) throws SQLException {
if(item.hasUploadedFiles()){
Metadatum[] mds = item.getMetadataByMetadataString("dc.rights.uri");
if(mds.length != 1){
System.out.println("ERR: Item " + item.getID() + " has " + mds.length + " dc.rights.uri");
}else{
String uri = mds[0].value;
// this should be fine we've checked hasUploadedFiles
Bitstream b = item.getNonInternalBitstreams()[0];
List<LicenseResourceMapping> mappings = f.getAllMappings(b.getID());
for(LicenseResourceMapping mapping : mappings){
if(mapping.isActive()){
if(!uri.equals(mapping.getLicenseDefinition().getDefinition())){
System.out.println("ERR: Item " + item.getID() + " has dc.rights.uri " + uri + " " +
"but database has " + mapping.getLicenseDefinition().getDefinition());
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import java.util.Set;


import cz.cuni.mff.ufal.lindat.utilities.hibernate.*;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
Expand All @@ -20,10 +22,6 @@
import org.dspace.handle.HandleManager;
import static org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer.encodeForURL;

import cz.cuni.mff.ufal.lindat.utilities.hibernate.LicenseResourceMapping;
import cz.cuni.mff.ufal.lindat.utilities.hibernate.LicenseResourceUserAllowance;
import cz.cuni.mff.ufal.lindat.utilities.hibernate.UserMetadata;
import cz.cuni.mff.ufal.lindat.utilities.hibernate.UserRegistration;
import cz.cuni.mff.ufal.lindat.utilities.interfaces.IFunctionalities;

/**
Expand All @@ -49,7 +47,7 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque

int eID = 0;
EPerson eperson = context.getCurrentUser();
if(eperson!=null) {
if (eperson != null) {
eID = eperson.getID();
}

Expand Down Expand Up @@ -78,7 +76,7 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque
actions.add(exField);
}
}

StringBuilder ids = new StringBuilder();

functionalityManager.openSession();
Expand All @@ -96,6 +94,12 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque
bss[0] = Bitstream.find(context, requestedBitstreamId);
}

for (LicenseDefinition ld : functionalityManager.getLicenses(bss[0].getID())) {
// LicenseForm.LicenseConfirmation.ALLOW_ANONYMOUS
if (ld.getConfirmation() != 3 && eID == 0) {
throw new AuthorizeException("Anonymous user is not allowed to download this file. Please login.");
}
}
String token = Utils.generateHexKey();

for (Bitstream bitstream : bss) {
Expand Down Expand Up @@ -128,7 +132,7 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque

functionalityManager.update(LicenseResourceUserAllowance.class, allowance);
}

// add IP address
UserMetadata metaData = new UserMetadata();
metaData.setMetadataKey("IP");
Expand All @@ -138,7 +142,7 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque
functionalityManager.persist(UserMetadata.class, metaData);

functionalityManager.update(LicenseResourceUserAllowance.class, allowance);


}

Expand All @@ -163,11 +167,11 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque
/*
* AK: this is not working well with some requirements commenting
* this out for now.
*
*
* After signing the license add the bitstream to session so that
* for the current session the system will not check for licenses
* again
*
*
* HttpSession session =
* dspace.getSessionService().getCurrentSession(); String
* authorizedBistreams = (String)
Expand Down Expand Up @@ -210,6 +214,10 @@ public String agree(Context context, Map objectModel, boolean allzip, int reque
return contextPath + "/handle/" + handle;
}

} catch (AuthorizeException e){
log.error(e);
functionalityManager.close();
throw new RuntimeException(e);
} catch (Exception e) {
log.error(e);
functionalityManager.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void addBody(Body body) throws SAXException, WingException,

div.setHead(T_head);

div.addPara(T_info1);
div.addPara(T_info1.parameterize(collection.getName()));

// add standard control/paging buttons
List list = div.addList( "submit-showinfo-controls", List.TYPE_FORM );
Expand Down
10 changes: 6 additions & 4 deletions dspace-xmlui/src/main/webapp/i18n/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3290,6 +3290,8 @@
<message key="input_forms.field.dc.alternate.identifiers.hint">The item will get a handle. If the item has any
identification numbers or codes associated with it, please enter the types and the actual numbers or codes.
</message>
<message key="input_forms.field.local.demo.uri2.label">Course homepage</message>
<message key="input_forms.field.dc.type.teaching.hint">This is here to autofill a value. The value should not be changed.</message>

<!-- cz.cuni.mff.ufal.ContractPage -->
<message key="xmlui.ContractPage.title">Distribution License Agreement</message>
Expand All @@ -3300,10 +3302,10 @@
<!-- cz.cuni.mff.ufal.dspace.app.xmlui.aspect.submission.submit.ShowInfoStep -->
<message key="xmlui.Submission.submit.progressbar.showinfo">Notice</message>
<message key="xmlui.Submission.submit.ShowInfoStep.head">Notice</message>
<message key="xmlui.Submission.submit.ShowInfoStep.info1">The submission process for digital humanities
collections is still being fine tuned. If you find yourself not being able to continue the submission,
because you can't provide the required information, or because the required format for a field is too strict, or
because there's no appropriate field for your information or for any other reason,
<message key="xmlui.Submission.submit.ShowInfoStep.info1">The submission process for this collection ("{0}") is
still being fine-tuned. If you find yourself unable to continue the submission because you can't
provide the required information, because the required format for a field is too strict, because there's
no appropriate field for your information, or for any other reason
<a class="helpdesk-tolink">let us know</a>.</message>

</catalogue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1502,3 +1502,8 @@ div.modal-scrollbar {
margin-left: 100px;
}
}

li:has(select.hide-me){
display: none !important;
visibility: hidden !important;
}
Loading

0 comments on commit 8a6ba5c

Please sign in to comment.