Skip to content

Commit

Permalink
Merge pull request #1136 from ufal/dataquest/dtq-dev
Browse files Browse the repository at this point in the history
merging dataquest-dev/dtq dev
  • Loading branch information
kosarko authored Nov 21, 2024
2 parents 0dcd935 + 1bd8967 commit 79fb64d
Show file tree
Hide file tree
Showing 50 changed files with 10,129 additions and 389 deletions.
16 changes: 16 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/util/DCInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public class DCInput {
*/
private ComplexDefinition complexDefinition = null;

/**
* give suggestions from this specific autocomplete solr index/file
*/
private String autocompleteCustom = null;

/**
* the dropdown input type could have defined a default value
*/
Expand Down Expand Up @@ -235,6 +240,9 @@ public DCInput(Map<String, String> fieldMap, Map<String, List<String>> listMap,
if ("complex".equals(inputType)) {
complexDefinition = complexDefinitions.getByName((fieldMap.get(DCInputsReader.COMPLEX_DEFINITION_REF)));
}
if ("autocomplete".equals(inputType)) {
autocompleteCustom = fieldMap.get(DCInputsReader.AUTOCOMPLETE_CUSTOM);
}
hint = fieldMap.get("hint");
warning = fieldMap.get("required");
required = warning != null && warning.length() > 0;
Expand Down Expand Up @@ -725,6 +733,14 @@ public boolean isMetadataField() {
return isMetadataField;
}

public String getAutocompleteCustom() {
return autocompleteCustom;
}

public void setAutocompleteCustom(String autocompleteCustom) {
this.autocompleteCustom = autocompleteCustom;
}

/**
* Class representing a Map of the ComplexDefinition object
* Class is copied from UFAL/CLARIN-DSPACE (https://github.com/ufal/clarin-dspace) and modified by
Expand Down
10 changes: 10 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/util/DCInputsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public class DCInputsReader {
static final String COMPLEX_DEFINITION_REF = "complex-definition-ref";
public static final String TYPE_BIND_FIELD_ATTRIBUTE = "field";

/**
* Keyname for storing the name of the custom autocomplete input type
*/
static final String AUTOCOMPLETE_CUSTOM = "autocomplete-custom";


/**
* Reference to the forms definitions map, computed from the forms
Expand Down Expand Up @@ -552,6 +557,11 @@ private void handleInputTypeTagName(String formName, Map<String, String> field,
} else {
field.put(COMPLEX_DEFINITION_REF, definitionName);
}
} else if (value.equals("autocomplete")) {
String definitionName = getAttribute(nd, AUTOCOMPLETE_CUSTOM);
if (definitionName != null) {
field.put(AUTOCOMPLETE_CUSTOM, definitionName);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,25 @@ public int authenticate(Context context, String username, String password,

// The user e-mail is not stored in the `shibheaders` but in the `clarinVerificationToken`.
// The email was added to the `clarinVerificationToken` in the ClarinShibbolethFilter.
String netidHeader = configurationService.getProperty("authentication-shibboleth.netid-header");
clarinVerificationToken = clarinVerificationTokenService.findByNetID(context,
shibheaders.get_single(netidHeader));
String[] netidHeaders = configurationService.getArrayProperty("authentication-shibboleth.netid-header");

// Load the verification token from the request header or from the request parameter.
// This is only set if the user is trying to authenticate with the `verification-token`.
String VERIFICATION_TOKEN = "verification-token";
String verificationTokenFromRequest = StringUtils.defaultIfBlank(request.getHeader(VERIFICATION_TOKEN),
request.getParameter(VERIFICATION_TOKEN));
if (StringUtils.isNotEmpty(verificationTokenFromRequest)) {
log.info("Verification token from request header `{}`: {}", VERIFICATION_TOKEN,
verificationTokenFromRequest);
clarinVerificationToken = clarinVerificationTokenService.findByToken(context, verificationTokenFromRequest);
}
// CLARIN

// Initialize the additional EPerson metadata.
initialize(context);

// Should we auto register new users.
boolean autoRegister = configurationService.getBooleanProperty("authentication-shibboleth.autoregister", true);
String[] netidHeaders = configurationService.getArrayProperty("authentication-shibboleth.netid-header");

// Four steps to authenticate a user
try {
Expand Down
11 changes: 11 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/WorkspaceItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class WorkspaceItem
@Column(name = "page_reached")
private Integer pageReached = -1;

@Column(name = "share_token")
private String shareToken = null;

/**
* Protected constructor, create object using:
* {@link org.dspace.content.service.WorkspaceItemService#create(Context, Collection, boolean)}
Expand Down Expand Up @@ -131,6 +134,14 @@ public void setPageReached(int v) {
pageReached = v;
}

public String getShareToken() {
return shareToken;
}

public void setShareToken(String shareToken) {
this.shareToken = shareToken;
}

/**
* Decide if this WorkspaceItem is equal to another
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public WorkspaceItem findByItem(Context context, Item item) throws SQLException
return workspaceItemDAO.findByItem(context, item);
}

@Override
public List<WorkspaceItem> findByShareToken(Context context, String shareToken) throws SQLException {
return workspaceItemDAO.findByShareToken(context, shareToken);
}

@Override
public List<WorkspaceItem> findAll(Context context) throws SQLException {
return workspaceItemDAO.findAll(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Objects;

import org.apache.commons.lang.NullArgumentException;
import org.dspace.authenticate.clarin.ShibHeaders;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.dao.clarin.ClarinVerificationTokenDAO;
Expand Down Expand Up @@ -75,6 +76,19 @@ public ClarinVerificationToken findByNetID(Context context, String netID) throws
return clarinVerificationTokenDAO.findByNetID(context, netID);
}

@Override
public ClarinVerificationToken findByNetID(Context context, String[] netIdHeaders, ShibHeaders shibHeaders)
throws SQLException {
for (String netidHeader : netIdHeaders) {
String netID = shibHeaders.get_single(netidHeader);
ClarinVerificationToken clarinVerificationToken = clarinVerificationTokenDAO.findByNetID(context, netID);
if (Objects.nonNull(clarinVerificationToken)) {
return clarinVerificationToken;
}
}
return null;
}

@Override
public void delete(Context context, ClarinVerificationToken clarinVerificationToken)
throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public List<WorkspaceItem> findByEPerson(Context context, EPerson ep, Integer li

public WorkspaceItem findByItem(Context context, Item i) throws SQLException;

public List<WorkspaceItem> findByShareToken(Context context, String shareToken) throws SQLException;

public List<WorkspaceItem> findAll(Context context) throws SQLException;

public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public WorkspaceItem findByItem(Context context, Item i) throws SQLException {
return uniqueResult(context, criteriaQuery, false, WorkspaceItem.class);
}

@Override
public List<WorkspaceItem> findByShareToken(Context context, String shareToken) throws SQLException {
Query query = createQuery(context,
"from WorkspaceItem ws where ws.shareToken = :shareToken");
query.setParameter("shareToken", shareToken);
return list(query);
}

@Override
public List<WorkspaceItem> findAll(Context context) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public List<WorkspaceItem> findByCollection(Context context, Collection collecti
public WorkspaceItem findByItem(Context context, Item item)
throws SQLException;

/**
* Find the workspace item by the share token.
* @param context the DSpace context object
* @param shareToken the share token
* @return the List of workspace items or null
* @throws SQLException if database error
*/
public List<WorkspaceItem> findByShareToken(Context context, String shareToken)
throws SQLException;

/**
* Get all workspace items in the whole system
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.sql.SQLException;
import java.util.List;

import org.dspace.authenticate.clarin.ShibHeaders;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.clarin.ClarinVerificationToken;
import org.dspace.core.Context;
Expand Down Expand Up @@ -69,6 +70,18 @@ public interface ClarinVerificationTokenService {
*/
ClarinVerificationToken findByNetID(Context context, String netID) throws SQLException;

/**
* Find the clarin verification token object from the shibboleth headers trying every netId header
* until the object is found
* @param context DSpace context object
* @param netIdHeaders array of the netId headers - values from the configuration
* @param shibHeaders object with the shibboleth headers
* @return found clarin verification token object or null
* @throws SQLException if database error
*/
ClarinVerificationToken findByNetID(Context context, String[] netIdHeaders, ShibHeaders shibHeaders)
throws SQLException;

/**
* Remove the clarin verification token from DB
* @param context DSpace context object
Expand Down
17 changes: 17 additions & 0 deletions dspace-api/src/main/java/org/dspace/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,21 @@ public static String interpolateConfigsInString(String string) {
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
return StringSubstitutor.replace(string, config.getProperties());
}

/**
* Replace the last occurrence of a substring within a string.
*
* @param input The input string
* @param toReplace The substring to replace
* @param replacement The replacement substring
* @return Replaced input string or the original input string if the substring to replace is not found
*/
public static String replaceLast(String input, String toReplace, String replacement) {
int lastIndex = input.lastIndexOf(toReplace);
if (lastIndex == -1) {
return input; // No replacement if not found
}

return input.substring(0, lastIndex) + replacement + input.substring(lastIndex + toReplace.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,28 @@ public void addDiscoveryFields(SolrInputDocument doc, Context context, Item item
}



// process item metadata
// just add _comp to local*
List<MetadataValue> mds = itemService.getMetadata(item, "local", Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue meta : mds) {
String field = "local" + "." + meta.getMetadataField().getElement();
String value = meta.getValue();
if (value == null) {
continue;
}
String qualifier = meta.getMetadataField().getQualifier();
if (qualifier != null && !qualifier.isEmpty()) {
field += "." + qualifier;
}
doc.addField(field + "_comp", value);
}

// create handle_title_ac field
String title = item.getName();
String handle = item.getHandle();
doc.addField("handle_title_ac", handle + ":" + title);

log.debug(" Added Metadata");

try {
Expand Down
Loading

0 comments on commit 79fb64d

Please sign in to comment.