Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DBT-326 add DBTStrategy and SOLR configuration #198

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions src/main/java/de/urmel_dl/dbt/authorization/DBTStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package de.urmel_dl.dbt.authorization;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.MCRSessionMgr;
import org.mycore.common.MCRUserInformation;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.common.MCRCreatorCache;
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.mir.authorization.MIRStrategy;

public class DBTStrategy extends MIRStrategy {
private static Logger LOGGER = LogManager.getLogger();

private static final String FLAG_TYPE = "dbt-dini";

private static final String FLAG_VALUE = "exclude";

private static final String CREATOR_ROLE = MCRConfiguration2.getString("MCR.Access.Strategy.CreatorRole")
.orElse("submitter");

@Override
public boolean checkPermission(String id, String permission) {
final boolean hasPermission = super.checkPermission(id, permission);
return hasPermission || checkPermissionForNonDINI(id, permission);
}

private boolean checkPermissionForNonDINI(String id, String permission) {
if (!MCRObjectID.isValid(id)) {
return false;
}
final MCRObjectID mcrId = MCRObjectID.getInstance(id);
MCRUserInformation currentUser = MCRSessionMgr.getCurrentSession().getUserInformation();
return currentUser.isUserInRole(CREATOR_ROLE) && isCurrentUserCreator(mcrId, currentUser)
&& isNonDINIDocument(mcrId);

}

private static boolean isCurrentUserCreator(MCRObjectID mcrId, MCRUserInformation currentUser) {
try {
String creator = MCRCreatorCache.getCreator(mcrId);
return currentUser.getUserID().equals(creator);
} catch (ExecutionException e) {
LOGGER.error("Error while getting creator information.", e);
return false;
}
}

private static boolean isNonDINIDocument(MCRObjectID mcrId) {
MCRObjectID objectID = "derivate".equals(mcrId.getTypeId())
? MCRMetadataManager.getObjectId(mcrId, 1, TimeUnit.DAYS)
: mcrId;
if (objectID == null) {
LOGGER.error("Could not find object id to {}.", mcrId);
return false;
}
final MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
return obj.getService().getFlags(FLAG_TYPE).contains(FLAG_VALUE);
}

}
24 changes: 23 additions & 1 deletion src/main/resources/META-INF/resources/editor/editor-dbt.xed
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</select>
</div>
<div class="col-md-3">
<a tabindex="0" class="btn btn-default info-button" role="button" data-toggle="popover" data-placement="right" data-content="{i18n:editor.oai.help}">
<a tabindex="0" class="btn btn-secondary info-button" role="button" data-toggle="popover" data-placement="right" data-content="{i18n:editor.oai.help}">
<i class="fa fa-info"></i>
</a>
</div>
Expand All @@ -80,4 +80,26 @@
<xed:include ref="oai" after="institutes" />
</xed:modify>

<xed:template id="dbt.diniExclude">
<xed:bind xpath="service/servflags[@class='MCRMetaLangText']/servflag[@type='dbt-dini']">
<div class="form-group row bg-light border border-primary pt-2 {$xed-validation-marker}">
<label class="col-md-3 control-label text-right">
<xed:output i18n="editor.diniExclude"/>
</label>
<div class="col-md-6">
<input type="checkbox" value="exclude"/>
</div>
<div class="col-md-3">
<a tabindex="0" class="btn btn-secondary info-button" role="button" data-toggle="popover" data-placement="right"
data-content="{i18n:editor.diniExclude.help}">
<i class="fa fa-info"></i>
</a>
</div>
</div>
</xed:bind>
</xed:template>
<xed:modify ref="mycore.common">
<xed:include ref="dbt.diniExclude" before="*" />
</xed:modify>

</xed:template>
2 changes: 2 additions & 0 deletions src/main/resources/config/dbt/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ editor.contract.disagree = Ich lehne ab
editor.contract.publish = D\u00FCrfen wir ver\u00F6ffentlichen?
editor.contract.text = Ich habe den <a href="../content/publish/contract.xml" target="_blank">Ver\u00F6ffentlichungsvertrag</a> gelesen und stimme ihm zu. Insbesondere versichere ich, dass mit der Bereitstellung dieses Werkes keine Rechte Dritter, insbesondere aus dem geltenden Urheberrecht, verletzt werden.
editor.contract.validation = Bitte stimmen Sie der Ver\u00F6ffentlichung zu.
editor.diniExclude = Kurzzeit-Dokument "Digitales\u00A0SoSe\u00A02020"
editor.diniExclude.help = Wenn die Auswahlbox gew\u00E4hlt wird, ist dieses Dokument vom urspr\u00FCnglichen Einsender auch im Status "ver\u00F6ffentlicht" noch \u00E4nder- und l\u00F6schbar. Es bekommt keinen persistenten Identifikator und ist nicht \u00FCber OAI sichtbar.
editor.oai = OAI Freigabe
editor.oai.help = W\u00E4hlen Sie hier aus f\u00FCr wenn das Dokument in der OAI Schnittstelle freigegeben werden soll.

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/dbt/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ editor.contract.disagree = I disagree
editor.contract.publish = May we publish?
editor.contract.text = I have read the <a href="../content/publish/contract.xml" target="_blank">publication contract (in German only)</a> and I agree. In particular, I assure that the provision of this work does not infringe any rights of third parties, in particular under applicable copyright laws.
editor.contract.validation = Please agree to the publication contract.
editor.diniExclude = Short-living document "digital\u00A0summer\u00A0semester\u00A02020"
editor.diniExclude.help = If checkbox is selected the document can still be changed and deleted by the original submitter, if the stat is published. The document will not be visible by OAI and will not get a persistent identifier.
editor.oai = OAI enabling
editor.oai.help = Chose who can access the document over the OAI interface.

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/config/dbt/mycore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,12 @@ MCR.Access.Strategy.SubmittedCategory=%MCR.Access.Strategy.SubmittedCategory%,st

MCR.ContentTransformer.deepgreenjats2mods.Class=org.mycore.common.content.transformer.MCRXSLTransformer
MCR.ContentTransformer.deepgreenjats2mods.Stylesheet=xsl/sword/jats2mods.xsl

######################################################################
# Digital Summer Semester 2020 DBT-326
######################################################################
MCR.OAIDataProvider.OAI2.Search.Restriction=+objectType\:mods -dbt.dini\:exclude
MCR.Access.Strategy.Class=de.urmel_dl.dbt.authorization.DBTStrategy
MIR.AccessKeyStrategy.FallbackClass=de.urmel_dl.dbt.authorization.DBTStrategy
MIR.OwnerStrategy.FallbackClass=de.urmel_dl.dbt.authorization.DBTStrategy
MCR.URIResolver.xslImports.solr-document=%MCR.URIResolver.xslImports.solr-document%,dbt-solr.xsl
6 changes: 6 additions & 0 deletions src/main/resources/config/dbt/solr/main/solr-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@
"name": "slotId",
"type": "string"
}
},
{
"add-field": {
"name": "dbt.dini",
"type": "string"
}
}
]
17 changes: 17 additions & 0 deletions src/main/resources/xsl/dbt-solr.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="xslImport:solr-document:dbt-solr.xsl"/>

<xsl:template match="mycoreobject[contains(@ID,'_mods_')]">
<xsl:apply-imports/>
<xsl:apply-templates select="service/servflags/servflag[@type='dbt-dini']" mode="dbt"/>
</xsl:template>

<xsl:template match="servflag[@type='dbt-dini']" mode="dbt">
<field name="dbt.dini">
<xsl:value-of select="."/>
</field>
</xsl:template>

</xsl:stylesheet>