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

Issue 289 #491

Merged
merged 4 commits into from
Apr 6, 2016
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,75 @@
package cz.cuni.mff.ufal.curation;

import org.apache.commons.io.IOUtils;
import org.dspace.content.*;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator;

public class DepositLicenseCheck extends AbstractCurationTask {

private String msg = null;
private int status = Curator.CURATE_UNSET;

@Override
public int perform(DSpaceObject dso) {
if(dso.getType() == Constants.ITEM){
Item item = (Item)dso;
//everything OK unless prove otherwise
msg = String.format("Item %s OK", item.getHandle());
status = Curator.CURATE_SUCCESS;
try {
Collection col = item.getOwningCollection();
String colLicense = col.getLicense();
//we have some deposited content
if(item.getBundles("ORIGINAL").length > 0 && item.getBundles("ORIGINAL")[0].getBitstreams().length > 0) {
//if we have a license check if it's ok or some junk.
if (item.getBundles("LICENSE").length == 1 && item.getBundles("LICENSE")[0].getBitstreams().length == 1) {
Bundle bundle = item.getBundles("LICENSE")[0];
Bitstream bit = bundle.getBitstreams()[0];
String bitLicense = IOUtils.toString(bit.retrieve(), "UTF-8");
if (!colLicense.equals(bitLicense)) {
//This is the generic "Replace me" license, use colLicense instead
if (bitLicense != null && bitLicense.contains(placeholderLicenseText)) {
item.removeDSpaceLicense();
Context context = new Context();
LicenseUtils.grantLicense(context, item, colLicense);
context.complete();
msg = String.format("Replaced default \"placeholder\" deposit license in %s", item.getHandle());
//Something unexpected, just report
} else {
msg = String.format("Deposit license for item %s (/xmlui/bitstream/id/%s/?sequence=%s) and collection %s differ.",
item.getHandle(), bit.getID(), bit.getSequenceID(), col.getName());
status = Curator.CURATE_FAIL;
}
}
//there is no license bundle or bitstream, add it
} else if (item.getBundles("LICENSE").length == 0 || (item.getBundles("LICENSE").length == 1 && item.getBundles("LICENSE")[0].getBitstreams().length == 0)) {
//if the bundle is there remove it
item.removeDSpaceLicense();
Context context = new Context();
LicenseUtils.grantLicense(context, item, colLicense);
context.complete();
msg = String.format("Adding missing deposit license for %s", item.getHandle());
} else {
throw new Exception("More than one LICENSE bundles or license bitstreams.");
}
}
} catch (Exception e) {
msg = String.format("Exception while running DepositLicenseCheck on %s: %s", item.getHandle(), e.getMessage());
status = Curator.CURATE_ERROR;
}

} else {
status = Curator.CURATE_SKIP;
}
if(msg != null){
report(msg);
setResult(msg);
}
return status;
}

private String placeholderLicenseText = "NOTE: PLACE YOUR OWN LICENSE HERE";
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static String getLicenseText(String licenseFile)
InputStream is = null;
InputStreamReader ir = null;
BufferedReader br = null;
String license;
try
{
is = new FileInputStream(licenseFile);
Expand Down
83 changes: 83 additions & 0 deletions dspace-xmlui/src/main/java/cz/cuni/mff/ufal/ContractPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Created for LINDAT/CLARIN */
package cz.cuni.mff.ufal;

import org.apache.cocoon.ProcessingException;
import org.apache.xalan.xsltc.util.IntegerArray;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.*;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.I18nUtil;
import org.dspace.core.LicenseManager;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.sql.SQLException;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class ContractPage extends AbstractDSpaceTransformer {

private static final Message T_dspace_home = message("xmlui.general.dspace_home");
private static final Message T_title = message("xmlui.ContractPage.title");
private static final Message T_trail = message("xmlui.ContractPage.trail");
private static final Message T_head = message("xmlui.ContractPage.head");
private static final Message T_collection_name = message("xmlui.ContractPage.collection_name");
private static final Message T_explain_non_localized_license = message("xmlui.ContractPage.explain_non_localized_license");

private static final String alternativeLicenseText;
static{
String alternativePath = ConfigurationManager.getProperty("lr","license.alternative.path");
if(isNotBlank(alternativePath)){
alternativeLicenseText = LicenseManager.getLicenseText(alternativePath);
}else{
alternativeLicenseText = null;
}
}



@Override
public void addPageMeta(PageMeta pageMeta) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}

@Override
public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException, ProcessingException {
Division division = body.addDivision("licenses", "well");

division.setHead(T_head);

boolean showExplanation = ConfigurationManager.getBooleanProperty("lr","license.show_localized_explanation", true);

if(!context.getCurrentLocale().equals(I18nUtil.getDefaultLocale()) && showExplanation ){
division.addPara().addContent(T_explain_non_localized_license);
if(isNotBlank(alternativeLicenseText)){
addLicense(division, "default_license_alternative", T_collection_name.parameterize("Default license"),
alternativeLicenseText);
}
}

for(Collection col : Collection.findAll(context)){
addLicense(division, Integer.toString(col.getID()), T_collection_name.parameterize(col.getName()), col.getLicense());
}
}

private void addLicense(Division division, String id, Message head, String text) throws WingException {
Division license = division.addDivision("license_" + id, "well well-sm well-white");
license.setHead(head);
TextArea textArea = license.addPara().addTextArea("license_text_" + id);
textArea.setSize(34,0); //cols are overridden by .form-control
textArea.setValue(text);
textArea.setDisabled();
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ collections / items / and bitstreams.
<map:transformer name="ConfigurableBrowse" src="org.dspace.app.xmlui.aspect.artifactbrowser.ConfigurableBrowse"/>
<map:transformer name="StaticPage" src="cz.cuni.mff.ufal.dspace.app.xmlui.aspect.browseArtifacts.StaticPage"/>
<map:transformer name="LicensePage" src="cz.cuni.mff.ufal.LicensePage"/>
<map:transformer name="ContractPage" src="cz.cuni.mff.ufal.ContractPage"/>
</map:transformers>

<map:matchers default="wildcard">
Expand Down Expand Up @@ -67,6 +68,11 @@ collections / items / and bitstreams.
<map:serialize type="xml"/>
</map:match>

<map:match pattern="page/contract">
<map:transform type="ContractPage" />
<map:serialize type="xml" />
</map:match>

<map:match pattern="page/*">
<map:transform type="StaticPage"/>
<map:serialize type="xml"/>
Expand Down
7 changes: 7 additions & 0 deletions dspace-xmlui/src/main/webapp/i18n/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3203,5 +3203,12 @@
<message key="input_forms.complex_definitions.funding.3_projname.label">Funding project name</message>
<message key="input_forms.complex_definitions.funding.5_openaire_id.label">EU Project Identifier (OpenAIRE)</message>
<message key="input_forms.complex_definitions.sizeInfo.2_unit.label">Unit</message>

<!-- cz.cuni.mff.ufal.ContractPage -->
<message key="xmlui.ContractPage.title">Distribution License Agreement</message>
<message key="xmlui.ContractPage.trail">Distribution License Agreement</message>
<message key="xmlui.ContractPage.head">Distribution License Agreement</message>
<message key="xmlui.ContractPage.collection_name">{0}</message>

</catalogue>

39 changes: 0 additions & 39 deletions dspace-xmlui/src/main/webapp/themes/UFAL/lib/html/contract.html

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions dspace-xmlui/src/main/webapp/themes/UFAL/lib/html/cs/contract.html

This file was deleted.

This file was deleted.

28 changes: 28 additions & 0 deletions dspace/config/alternative.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
NEVÝHRADNÍ LICENCE NA DISTRIBUCI

Podpisem a odesláním této licence vy (autor/autoři nebo vlastník/vlastníci autorských práv) udělujete
Univerzitě Karlově v Praze (UK) nevýhradní právo celosvětově reprodukovat,
překládat (jak je definováno níže) a/nebo distribuovat vaše příspěvky (včetně abstraktů)
v tištěné i elektronické podobě a za pomoci jakéhokoli média (včetně audia nebo videa, ale i jakýchkoliv jiných médií).

Souhlasíte s tím, že UK může, pokud nezmění obsah, převést váš příspěvek do jakéhokoli formátu
nebo na jakékoli médium za účelem jeho uchování.

Rovněž souhlasíte, že UK si může ponechat více než jednu kopii tohoto příspěvku pro
účely jeho bezpečnosti, zálohování a dlouhodobého uchovávání.

Prohlašujete, že váš příspěvek k dílu je původní a že máte právo udělovat práva uvedená v této licenci k celému dílu.
Prohlašujete také, že podle vašeho nejlepšího vědomí a svědomí, neporušujete tímto ničí autorská práva.

V případě, že příspěvek obsahuje materiál, pro který nevlastníte autorská práva,
prohlašujete, že jste obdržel(i) neomezené povolení
vlastníka autorských práv udělit UK práva požadovaná touto licencí a že
takový materiál ve vlastnictví třetí strany je zřetelně označen a citován
v textu nebo obsahu vašeho příspěvku.

POKUD JE PŘÍSPĚVEK ZALOŽEN NA PRÁCI, KTERÁ BYLA SPONZOROVÁNA NEBO PODPOROVÁNA JAKOUKOLI JINOU AGENTUROU NEBO ORGANIZACÍ,
NEŽ JE UK, PROHLAŠUJETE, ŽE JSTE SPLNIL(I) VŠECHNA PRÁVA NA PŘEZKOUMÁNÍ A TAKÉ JINÉ ZÁVAZKY
VYŽADOVANÉ TAKOVOUTO SMLOUVOU NEBO UJEDNÁNÍM.

UK bude jasně identifikovat vaše jméno (jména) jako autora (autorů) nebo vlastníka (vlastníků)
poskytnutého díla a nebude provádět žádné jiné změny tohoto díla než ty, které povoluje tato licence.
6 changes: 4 additions & 2 deletions dspace/config/modules/curate.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ plugin.named.org.dspace.curate.CurationTask = \
cz.cuni.mff.ufal.curation.OpenAIRE = openaire, \
cz.cuni.mff.ufal.curation.FixOpenAIREMetadata = fixopenaire, \
cz.cuni.mff.ufal.curation.FastLinkChecker = fastchecklinks, \
cz.cuni.mff.ufal.curation.ProcessBitstreams = processbitstreams
cz.cuni.mff.ufal.curation.ProcessBitstreams = processbitstreams, \
cz.cuni.mff.ufal.curation.DepositLicenseCheck = depositlicense
# add new tasks here

## task queue implementation
Expand All @@ -46,7 +47,8 @@ ui.tasknames = \
openaire = Check OpenAIRE items, \
fixopenaire = Fix OpenAIRE Metadata, \
checkmetadata = Check Metadata for Quality and Consistency, \
processbitstreams = Gather additional information from bitstreams
processbitstreams = Gather additional information from bitstreams, \
depositlicense = Check deposit license

# Tasks may be organized into named groups which display together in UI drop-downs
# ui.taskgroups = \
Expand Down
8 changes: 8 additions & 0 deletions dspace/config/modules/lr.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,13 @@ featured.service.pmltq.description = Tool for searching and browsing treebanks o
shortener.enabled = ${lr.shortener.enabled}
shortener.handle.prefix = ${lr.shortener.handle.prefix}

####
#
# License branding (https://github.com/ufal/lindat-dspace/issues/289)
#
####
license.alternative.path = ${dspace.dir}/config/alternative.license
license.show_localized_explanation = true

#build time
ufal.build_time=${lr.compile.time}
8 changes: 8 additions & 0 deletions dspace/modules/xmlui/src/main/webapp/i18n/messages_cs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3465,4 +3465,12 @@
<message key="input_forms.complex_definitions.funding.3_projname.label">Zdroj financí (jméno projektku)</message>
<message key="input_forms.complex_definitions.funding.5_openaire_id.label">EU Project Identifier (OpenAIRE)</message>
<message key="input_forms.complex_definitions.sizeInfo.2_unit.label">Jednotka</message>

<!-- cz.cuni.mff.ufal.ContractPage -->
<message key="xmlui.ContractPage.title">Smlouva o distribuci dat</message>
<message key="xmlui.ContractPage.trail">Smlouva o distribuci dat</message>
<message key="xmlui.ContractPage.head">Smlouva o distribuci dat</message>
<message key="xmlui.ContractPage.collection_name">{0}</message>
<message key="xmlui.ContractPage.explain_non_localized_license">Smlouva se uzavírá v angličtině a její plné znění naleznete níže. Následující český překlad je pouze orientační. V případě rozporů platí anglická verze. </message>

</catalogue>
Loading