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

Draft: AssociateItem Backend #382

Draft
wants to merge 7 commits into
base: dspace-cris-2023_02_x
Choose a base branch
from
Draft
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,66 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content.edit;

import org.dspace.content.Item;
import org.dspace.core.Context;

/**
* Class representing an item in the process of associate item triggered by a user.
* It is some wrapper if the {@AssociateItemMode} and the both items where the mode interacts.
*
* @author Danilo Di Nuzzo (danilo.dinuzzo at 4science.it)
* @author Florian Gantner ([email protected])
*
*/
public class AssociateItem {

private Item sourceitem;
private Item targetitem;
private AssociateItemMode mode;
private Context context;

public AssociateItem(Context context, Item sourceitem, Item targetitem, AssociateItemMode mode) {
this.context = context;
this.sourceitem = sourceitem;
this.mode = mode;
this.targetitem = targetitem;
}

public AssociateItemMode getMode() {
return mode;
}

public void setMode(AssociateItemMode mode) {
this.mode = mode;
}

public Item getTargetitem() {
return targetitem;
}

public void setTargetitem(Item targetitem) {
this.targetitem = targetitem;
}

public Item getSourceitem() {
return sourceitem;
}

public void setSourceitem(Item sourceitem) {
this.sourceitem = sourceitem;
}

public Context getContext() {
return context;
}

public void setContext(Context context) {
this.context = context;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content.edit;

import java.util.List;

import org.dspace.content.logic.DefaultFilter;
import org.dspace.content.logic.Filter;
import org.dspace.content.security.AccessItemMode;
import org.dspace.content.security.CrisSecurity;

/**
* This Class representing a modality of edit an item and adding some association to the item
*
* @author Danilo Di Nuzzo (danilo.dinuzzo at 4science.it)
* @author Florian Gantner ([email protected])
*/
public class AssociateItemMode implements AccessItemMode {

public static final String NONE = "none";
/**
* Configuration name
*/
private String name;

/**
* Discovery name
*/
private String discovery;

/**
* item Type Source
*/
private String itemTypeSource;

/**
* item Type Target
*/
private String itemTypeTarget;

/**
* Item type Metadatafield
*/

private String metadatafield;

/**
* Contains the condition for the item to be matched to fulfill to edit the source item
*/
private DefaultFilter conditionSource = null;

/**
* Contains the condition for the item to be matched to fulfill to edit the target item
*/
private DefaultFilter conditionTarget = null;

/**
* disable authorization check for editing source item
*/
private boolean disableAuthSource = false;

/**
* Label used in UI for i18n
*/
private String label;
/**
* Defines the users enabled to use this edit configuration
*/
private List<CrisSecurity> securities;

/**
* Contains the list of groups metadata for CUSTOM security or groups name/uuid
* for GROUP security
*/
private List<String> groups;
/**
* Contains the list of users metadata for CUSTOM security
*/
private List<String> users;
/**
* Contains the list of items metadata for CUSTOM security
*/
private List<String> items;

public AssociateItemMode() {}

@Override
public List<CrisSecurity> getSecurities() {
return securities;
}

public void setSecurity(CrisSecurity security) {
this.securities = List.of(security);
}

public void setSecurities(List<CrisSecurity> securities) {
this.securities = securities;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<String> getGroupMetadataFields() {
return groups;
}
public void setGroups(List<String> groups) {
this.groups = groups;
}
public List<String> getUserMetadataFields() {
return users;
}
public void setUsers(List<String> users) {
this.users = users;
}
public List<String> getItemMetadataFields() {
return items;
}
public void setItems(List<String> items) {
this.items = items;
}

@Override
public List<String> getGroups() {
return groups;
}

@Override
public Filter getAdditionalFilter() {
return null;
}

@Override
public String toString() {
return "AssociateItemMode [name=" + name + ", label=" + label + ", security=" + securities + ", discovery="
+ discovery + "]";
}

public boolean isdisableAuthSource() {
return disableAuthSource;
}

public DefaultFilter getConditionTarget() {
return conditionTarget;
}

public void setConditionTarget(DefaultFilter conditionTarget) {
this.conditionTarget = conditionTarget;
}

public DefaultFilter getConditionSource() {
return conditionSource;
}

public void setConditionSource(DefaultFilter conditionSource) {
this.conditionSource = conditionSource;
}

public String getItemTypeTarget() {
return itemTypeTarget;
}

public void setItemTypeTarget(String itemTypeTarget) {
this.itemTypeTarget = itemTypeTarget;
}

public String getItemTypeSource() {
return itemTypeSource;
}

public void setItemTypeSource(String itemTypeSource) {
this.itemTypeSource = itemTypeSource;
}

public void setDiscovery(String discovery) {
this.discovery = discovery;
}

public String getDiscovery() {
return discovery;
}

public String getMetadatafield() {
return metadatafield;
}

public void setMetadatafield(String metadatafield) {
this.metadatafield = metadatafield;
}

public void setDisableAuthSource(boolean disableAuthSource) {
this.disableAuthSource = disableAuthSource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content.edit.service;

import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.edit.AssociateItemMode;
import org.dspace.core.Context;

/**
* @author Danilo Di Nuzzo (danilo.dinuzzo at 4science.it)
* @author Florian Gantner ([email protected])
*
*/
public interface AssociateItemModeService {

static final String ASSOCIATEITEMMODECONF_PREFIX = "associatitem.mode.";

/**
* Finds all edit mode for the given item filtered by logged user privileges
* @param context DSpace context
* @param item
* @return
*/
List<AssociateItemMode> findModes(Context context, Item item) throws SQLException;

/**
* Finds all edit mode for the given item filtered by logged user privileges
* @param context DSpace context
* @param itemId id of item
* @return
*/
List<AssociateItemMode> findModes(Context context, UUID itemId) throws SQLException;

/**
* Finds an edit mode by item and edit name, returns null if not exists
* @param context DSpace context
* @param item UUID Item
* @param name edit mode name
* @return
* @throws SQLException
*/
AssociateItemMode findMode(Context context, Item item, String name) throws SQLException;

/**
* Check if the current user can edit the given item, based on the all the
* configured edit modes (verifying if there is at least one edit mode enabled
* for him).
*
* @param context the DSpace context
* @param item the item
* @return true if the given item is editable, false otherwise
*/
boolean canEdit(Context context, Item item);

public List<AssociateItemMode> findModes(Context context, Item item, boolean checkSecurity)
throws SQLException, AuthorizeException;
}
Loading