mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Replace deprecated setMetadata() that uses removed field names. #2956
Once upon a time, DSOs had dedicated fields for some metadata. These were moved into the Metadatavalue table long ago, but there were still methods which used the old field names instead of proper MetadataField triplets.
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.authenticate;
|
||||
|
||||
import static org.dspace.eperson.service.EPersonService.MD_PHONE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
@@ -321,7 +323,8 @@ public class LDAPAuthentication
|
||||
eperson.setLastName(context, ldap.ldapSurname);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ldap.ldapPhone)) {
|
||||
ePersonService.setMetadata(context, eperson, "phone", ldap.ldapPhone);
|
||||
ePersonService.setMetadataSingleValue(context, eperson,
|
||||
MD_PHONE, ldap.ldapPhone, null);
|
||||
}
|
||||
eperson.setNetid(netid.toLowerCase());
|
||||
eperson.setCanLogIn(true);
|
||||
|
@@ -24,11 +24,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataFieldName;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.MetadataSchemaEnum;
|
||||
import org.dspace.content.NonUniqueMetadataException;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
@@ -65,13 +68,12 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
* @author <a href="mailto:bliong@melcoe.mq.edu.au">Bruc Liong, MELCOE</a>
|
||||
* @author <a href="mailto:kli@melcoe.mq.edu.au">Xiang Kevin Li, MELCOE</a>
|
||||
* @author <a href="http://www.scottphillips.com">Scott Phillips</a>
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class ShibAuthentication implements AuthenticationMethod {
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(ShibAuthentication.class);
|
||||
private static final Logger log = LogManager.getLogger(ShibAuthentication.class);
|
||||
|
||||
/**
|
||||
* Additional metadata mappings
|
||||
@@ -843,25 +845,24 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
|
||||
// Truncate values
|
||||
if (value == null) {
|
||||
log.warn(
|
||||
"Unable to update the eperson's '" + field + "' metadata because the header '" + header + "' does" +
|
||||
" not exist.");
|
||||
log.warn("Unable to update the eperson's '{}' metadata"
|
||||
+ " because the header '{}' does not exist.", field, header);
|
||||
continue;
|
||||
} else if ("phone".equals(field) && value.length() > PHONE_MAX_SIZE) {
|
||||
log.warn(
|
||||
"Truncating eperson phone metadata because it is longer than " + PHONE_MAX_SIZE + ": '" + value +
|
||||
"'");
|
||||
log.warn("Truncating eperson phone metadata because it is longer than {}: '{}'",
|
||||
PHONE_MAX_SIZE, value);
|
||||
value = value.substring(0, PHONE_MAX_SIZE);
|
||||
} else if (value.length() > METADATA_MAX_SIZE) {
|
||||
log.warn(
|
||||
"Truncating eperson " + field + " metadata because it is longer than " + METADATA_MAX_SIZE + ": " +
|
||||
"'" + value + "'");
|
||||
log.warn("Truncating eperson {} metadata because it is longer than {}: '{}'",
|
||||
field, METADATA_MAX_SIZE, value);
|
||||
value = value.substring(0, METADATA_MAX_SIZE);
|
||||
}
|
||||
|
||||
ePersonService.setMetadata(context, eperson, field, value);
|
||||
log.debug(
|
||||
"Updated the eperson's '" + field + "' metadata using header: '" + header + "' = '" + value + "'.");
|
||||
String[] nameParts = MetadataFieldName.parse(field);
|
||||
ePersonService.setMetadataSingleValue(context, eperson,
|
||||
nameParts[0], nameParts[1], nameParts[2], value, null);
|
||||
log.debug("Updated the eperson's '{}' metadata using header: '{}' = '{}'.",
|
||||
field, header, value);
|
||||
}
|
||||
ePersonService.update(context, eperson);
|
||||
context.dispatchEvents();
|
||||
@@ -889,10 +890,8 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
protected int swordCompatibility(Context context, String username, String password, HttpServletRequest request)
|
||||
throws SQLException {
|
||||
|
||||
EPerson eperson = null;
|
||||
|
||||
log.debug("Shibboleth Sword compatibility activated.");
|
||||
eperson = ePersonService.findByEmail(context, username.toLowerCase());
|
||||
EPerson eperson = ePersonService.findByEmail(context, username.toLowerCase());
|
||||
|
||||
if (eperson == null) {
|
||||
// lookup failed.
|
||||
@@ -951,7 +950,7 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
}
|
||||
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
String[] mappingString = configurationService.getArrayProperty("authentication-shibboleth.eperson.metadata");
|
||||
boolean autoCreate = configurationService
|
||||
@@ -990,19 +989,19 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
|
||||
if (valid) {
|
||||
// The eperson field is fine, we can use it.
|
||||
log.debug("Loading additional eperson metadata mapping for: '" + header + "' = '" + name + "'");
|
||||
log.debug("Loading additional eperson metadata mapping for: '{}' = '{}'",
|
||||
header, name);
|
||||
map.put(header, name);
|
||||
} else {
|
||||
// The field doesn't exist, and we can't use it.
|
||||
log.error(
|
||||
"Skipping the additional eperson metadata mapping for: '" + header + "' = '" + name + "' because " +
|
||||
"the field is not supported by the current configuration.");
|
||||
log.error("Skipping the additional eperson metadata mapping for: '{}' = '{}'"
|
||||
+ " because the field is not supported by the current configuration.",
|
||||
header, name);
|
||||
}
|
||||
} // foreach metadataStringList
|
||||
|
||||
|
||||
metadataHeaderMap = map;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1020,12 +1019,8 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The phone is a predefined field
|
||||
if ("phone".equals(metadataName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MetadataField metadataField = metadataFieldService.findByElement(context, "eperson", metadataName, null);
|
||||
MetadataField metadataField = metadataFieldService.findByElement(context,
|
||||
MetadataSchemaEnum.EPERSON.getName(), metadataName, null);
|
||||
return metadataField != null;
|
||||
}
|
||||
|
||||
@@ -1063,10 +1058,7 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
try {
|
||||
context.turnOffAuthorisationSystem();
|
||||
metadataField = metadataFieldService.create(context, epersonSchema, metadataName, null, null);
|
||||
} catch (AuthorizeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return false;
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
} catch (AuthorizeException | NonUniqueMetadataException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return false;
|
||||
} finally {
|
||||
@@ -1211,7 +1203,7 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
// Shibboleth attributes are separated by semicolons (and semicolons are
|
||||
// escaped with a backslash). So here we will scan through the string and
|
||||
// split on any unescaped semicolons.
|
||||
List<String> valueList = new ArrayList<String>();
|
||||
List<String> valueList = new ArrayList<>();
|
||||
int idx = 0;
|
||||
do {
|
||||
idx = values.indexOf(';', idx);
|
||||
|
@@ -94,18 +94,6 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
@Transient
|
||||
private transient CollectionService collectionService;
|
||||
|
||||
// Keys for accessing Collection metadata
|
||||
@Transient
|
||||
public static final String COPYRIGHT_TEXT = "copyright_text";
|
||||
@Transient
|
||||
public static final String INTRODUCTORY_TEXT = "introductory_text";
|
||||
@Transient
|
||||
public static final String SHORT_DESCRIPTION = "short_description";
|
||||
@Transient
|
||||
public static final String SIDEBAR_TEXT = "side_bar_text";
|
||||
@Transient
|
||||
public static final String PROVENANCE_TEXT = "provenance_description";
|
||||
|
||||
/**
|
||||
* Protected constructor, create object using:
|
||||
* {@link org.dspace.content.service.CollectionService#create(Context, Community)}
|
||||
|
@@ -63,13 +63,13 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
joinColumns = {@JoinColumn(name = "parent_comm_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "child_comm_id")}
|
||||
)
|
||||
private Set<Community> subCommunities = new HashSet<>();
|
||||
private final Set<Community> subCommunities = new HashSet<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "subCommunities")
|
||||
private Set<Community> parentCommunities = new HashSet<>();
|
||||
private final Set<Community> parentCommunities = new HashSet<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "communities", cascade = {CascadeType.PERSIST})
|
||||
private Set<Collection> collections = new HashSet<>();
|
||||
private final Set<Collection> collections = new HashSet<>();
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "admin")
|
||||
@@ -83,12 +83,6 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
@JoinColumn(name = "logo_bitstream_id")
|
||||
private Bitstream logo = null;
|
||||
|
||||
// Keys for accessing Community metadata
|
||||
public static final String COPYRIGHT_TEXT = "copyright_text";
|
||||
public static final String INTRODUCTORY_TEXT = "introductory_text";
|
||||
public static final String SHORT_DESCRIPTION = "short_description";
|
||||
public static final String SIDEBAR_TEXT = "side_bar_text";
|
||||
|
||||
@Transient
|
||||
protected transient CommunityService communityService;
|
||||
|
||||
|
@@ -8,21 +8,23 @@
|
||||
package org.dspace.content;
|
||||
|
||||
/**
|
||||
* This is an enum that holds track of a few special MetadataSchema types.
|
||||
* This is an enumeration that holds track of a few special MetadataSchema types.
|
||||
* It is important to note that this list is not exhaustive for the MetadataSchema
|
||||
* types and different MetadataSchema can easily be made.
|
||||
* These MetadataSchema objects are simply required.
|
||||
*/
|
||||
public enum MetadataSchemaEnum {
|
||||
DC("dc"), RELATION("relation");
|
||||
DC("dc"),
|
||||
EPERSON("eperson"),
|
||||
RELATION("relation");
|
||||
|
||||
/**
|
||||
* The String representation of the MetadataSchemaEnum
|
||||
*/
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Default constructor with the name parameter
|
||||
* Default constructor with the name parameter.
|
||||
* @param name The name parameter
|
||||
*/
|
||||
MetadataSchemaEnum(String name) {
|
||||
@@ -30,8 +32,8 @@ public enum MetadataSchemaEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic getter for the String representation of the enum object
|
||||
* @return The name of the enum object
|
||||
* Generic getter for the String representation of the enumerated object.
|
||||
* @return The name of the enumerated object
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.eperson;
|
||||
|
||||
import static org.dspace.eperson.service.EPersonService.MD_PHONE;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -188,7 +190,8 @@ public class EPersonCLITool {
|
||||
eperson.setLastName(context, command.getOptionValue(OPT_SURNAME.getOpt()));
|
||||
eperson.setLanguage(context, command.getOptionValue(OPT_LANGUAGE.getOpt(),
|
||||
Locale.getDefault().getLanguage()));
|
||||
ePersonService.setMetadata(context, eperson, "phone", command.getOptionValue(OPT_PHONE.getOpt()));
|
||||
ePersonService.setMetadataSingleValue(context, eperson, MD_PHONE,
|
||||
command.getOptionValue(OPT_PHONE.getOpt()), null);
|
||||
eperson.setNetid(command.getOptionValue(OPT_NETID.getOpt()));
|
||||
ePersonService.setPassword(eperson, command.getOptionValue('p'));
|
||||
if (command.hasOption(OPT_REQUIRE_CERTIFICATE.getOpt())) {
|
||||
@@ -367,7 +370,8 @@ public class EPersonCLITool {
|
||||
modified = true;
|
||||
}
|
||||
if (command.hasOption(OPT_PHONE.getOpt())) {
|
||||
ePersonService.setMetadata(context, eperson, "phone", command.getOptionValue(OPT_PHONE.getOpt()));
|
||||
ePersonService.setMetadataSingleValue(context, eperson, MD_PHONE,
|
||||
command.getOptionValue(OPT_PHONE.getOpt()), null);
|
||||
modified = true;
|
||||
}
|
||||
if (command.hasOption(OPT_LANGUAGE.getOpt())) {
|
||||
|
@@ -549,7 +549,7 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
||||
|
||||
@Override
|
||||
public List<String> getDeleteConstraints(Context context, EPerson ePerson) throws SQLException {
|
||||
List<String> tableList = new ArrayList<String>();
|
||||
List<String> tableList = new ArrayList<>();
|
||||
|
||||
// check for eperson in item table
|
||||
Iterator<Item> itemsBySubmitter = itemService.findBySubmitter(context, ePerson, true);
|
||||
@@ -603,12 +603,6 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
||||
return getMetadataFirstValue(dso, MDValue[0], MDValue[1], MDValue[2], Item.ANY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Context context, EPerson ePerson, String field, String value) throws SQLException {
|
||||
String[] MDValue = getMDValueByLegacyField(field);
|
||||
setMetadataSingleValue(context, ePerson, MDValue[0], MDValue[1], MDValue[2], null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EPerson> findUnsalted(Context context) throws SQLException {
|
||||
return ePersonDAO.findWithPasswordWithoutDigestAlgorithm(context);
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
package org.dspace.eperson.service;
|
||||
|
||||
import static org.dspace.content.MetadataSchemaEnum.DC;
|
||||
import static org.dspace.content.MetadataSchemaEnum.EPERSON;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
@@ -48,13 +48,13 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
|
||||
// Common metadata fields which must be defined.
|
||||
|
||||
public static final MetadataFieldName MD_FIRSTNAME
|
||||
= new MetadataFieldName(DC, "firstname");
|
||||
= new MetadataFieldName(EPERSON, "firstname");
|
||||
public static final MetadataFieldName MD_LASTNAME
|
||||
= new MetadataFieldName(DC, "lastname");
|
||||
= new MetadataFieldName(EPERSON, "lastname");
|
||||
public static final MetadataFieldName MD_PHONE
|
||||
= new MetadataFieldName(DC, "phone");
|
||||
= new MetadataFieldName(EPERSON, "phone");
|
||||
public static final MetadataFieldName MD_LANGUAGE
|
||||
= new MetadataFieldName(DC, "language");
|
||||
= new MetadataFieldName(EPERSON, "language");
|
||||
|
||||
/**
|
||||
* Find the eperson by their email address.
|
||||
@@ -200,19 +200,6 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
|
||||
*/
|
||||
public boolean checkPassword(Context context, EPerson ePerson, String attempt);
|
||||
|
||||
/**
|
||||
* Set a metadata value (in the metadatavalue table) of the metadata field
|
||||
* specified by 'field'.
|
||||
*
|
||||
* @param context The relevant DSpace Context.
|
||||
* @param ePerson EPerson whose metadata we want to set.
|
||||
* @param field Metadata field we want to set (e.g. "phone").
|
||||
* @param value Metadata value we want to set
|
||||
* @throws SQLException if the requested metadata field doesn't exist
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMetadata(Context context, EPerson ePerson, String field, String value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Retrieve all accounts which have a password but do not have a digest algorithm
|
||||
*
|
||||
|
@@ -7,6 +7,13 @@
|
||||
*/
|
||||
package org.dspace.rest;
|
||||
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_COPYRIGHT_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_INTRODUCTORY_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_LICENSE;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_NAME;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SHORT_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SIDEBAR_TEXT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -60,7 +67,7 @@ public class CollectionsResource extends Resource {
|
||||
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
|
||||
protected WorkflowService workflowService = WorkflowServiceFactory.getInstance().getWorkflowService();
|
||||
|
||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(CollectionsResource.class);
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(CollectionsResource.class);
|
||||
|
||||
/**
|
||||
* Return instance of collection with passed id. You can add more properties
|
||||
@@ -179,7 +186,7 @@ public class CollectionsResource extends Resource {
|
||||
|
||||
log.info("Reading all collections.(offset=" + offset + ",limit=" + limit + ")");
|
||||
org.dspace.core.Context context = null;
|
||||
List<Collection> collections = new ArrayList<Collection>();
|
||||
List<Collection> collections = new ArrayList<>();
|
||||
|
||||
try {
|
||||
context = createContext();
|
||||
@@ -273,7 +280,7 @@ public class CollectionsResource extends Resource {
|
||||
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
|
||||
headers, request, context);
|
||||
|
||||
items = new ArrayList<Item>();
|
||||
items = new ArrayList<>();
|
||||
Iterator<org.dspace.content.Item> dspaceItems = itemService.findByCollection(context, dspaceCollection,
|
||||
limit, offset);
|
||||
|
||||
@@ -442,18 +449,20 @@ public class CollectionsResource extends Resource {
|
||||
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||
headers, request, context);
|
||||
|
||||
collectionService.setMetadata(context, dspaceCollection, "name", collection.getName());
|
||||
collectionService.setMetadata(context, dspaceCollection, "license", collection.getLicense());
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_NAME, collection.getName(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_LICENSE, collection.getLicense(), null);
|
||||
|
||||
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.COPYRIGHT_TEXT,
|
||||
collection.getCopyrightText());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.INTRODUCTORY_TEXT,
|
||||
collection.getIntroductoryText());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SHORT_DESCRIPTION,
|
||||
collection.getShortDescription());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SIDEBAR_TEXT,
|
||||
collection.getSidebarText());
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_COPYRIGHT_TEXT, collection.getCopyrightText(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_INTRODUCTORY_TEXT, collection.getIntroductoryText(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_SHORT_DESCRIPTION, collection.getShortDescription(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_SIDEBAR_TEXT, collection.getSidebarText(), null);
|
||||
collectionService.update(context, dspaceCollection);
|
||||
|
||||
context.complete();
|
||||
|
@@ -7,6 +7,13 @@
|
||||
*/
|
||||
package org.dspace.rest;
|
||||
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_COPYRIGHT_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_INTRODUCTORY_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_LICENSE;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_NAME;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SHORT_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SIDEBAR_TEXT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -51,7 +58,7 @@ public class CommunitiesResource extends Resource {
|
||||
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(CommunitiesResource.class);
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(CommunitiesResource.class);
|
||||
|
||||
/**
|
||||
* Returns community with basic properties. If you want more, use expand
|
||||
@@ -157,7 +164,7 @@ public class CommunitiesResource extends Resource {
|
||||
context = createContext();
|
||||
|
||||
List<org.dspace.content.Community> dspaceCommunities = communityService.findAll(context);
|
||||
communities = new ArrayList<Community>();
|
||||
communities = new ArrayList<>();
|
||||
|
||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0))) {
|
||||
log.warn("Paging was badly set, using default values.");
|
||||
@@ -233,7 +240,7 @@ public class CommunitiesResource extends Resource {
|
||||
context = createContext();
|
||||
|
||||
List<org.dspace.content.Community> dspaceCommunities = communityService.findAllTop(context);
|
||||
communities = new ArrayList<Community>();
|
||||
communities = new ArrayList<>();
|
||||
|
||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0))) {
|
||||
log.warn("Paging was badly set, using default values.");
|
||||
@@ -320,7 +327,7 @@ public class CommunitiesResource extends Resource {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
collections = new ArrayList<Collection>();
|
||||
collections = new ArrayList<>();
|
||||
List<org.dspace.content.Collection> dspaceCollections = dspaceCommunity.getCollections();
|
||||
for (int i = offset; (i < (offset + limit)) && (i < dspaceCollections.size()); i++) {
|
||||
if (authorizeService
|
||||
@@ -404,7 +411,7 @@ public class CommunitiesResource extends Resource {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
communities = new ArrayList<Community>();
|
||||
communities = new ArrayList<>();
|
||||
List<org.dspace.content.Community> dspaceCommunities = dspaceCommunity.getSubcommunities();
|
||||
for (int i = offset; (i < (offset + limit)) && (i < dspaceCommunities.size()); i++) {
|
||||
if (authorizeService
|
||||
@@ -479,15 +486,16 @@ public class CommunitiesResource extends Resource {
|
||||
writeStats(dspaceCommunity, UsageEvent.Action.CREATE, user_ip, user_agent, xforwardedfor,
|
||||
headers, request, context);
|
||||
|
||||
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT,
|
||||
community.getCopyrightText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT,
|
||||
community.getIntroductoryText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION,
|
||||
community.getShortDescription());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT,
|
||||
community.getSidebarText());
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_NAME, community.getName(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_COPYRIGHT_TEXT, community.getCopyrightText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_INTRODUCTORY_TEXT, community.getIntroductoryText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SHORT_DESCRIPTION, community.getShortDescription(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SIDEBAR_TEXT, community.getSidebarText(), null);
|
||||
communityService.update(context, dspaceCommunity);
|
||||
|
||||
retCommunity = new Community(dspaceCommunity, servletContext, "", context);
|
||||
@@ -553,17 +561,19 @@ public class CommunitiesResource extends Resource {
|
||||
writeStats(dspaceCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||
headers, request, context);
|
||||
org.dspace.content.Collection dspaceCollection = collectionService.create(context, dspaceCommunity);
|
||||
collectionService.setMetadata(context, dspaceCollection, "license", collection.getLicense());
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_LICENSE, collection.getLicense(), null);
|
||||
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
||||
collectionService.setMetadata(context, dspaceCollection, "name", collection.getName());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.COPYRIGHT_TEXT,
|
||||
collection.getCopyrightText());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.INTRODUCTORY_TEXT,
|
||||
collection.getIntroductoryText());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SHORT_DESCRIPTION,
|
||||
collection.getShortDescription());
|
||||
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SIDEBAR_TEXT,
|
||||
collection.getSidebarText());
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_NAME, collection.getName(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_COPYRIGHT_TEXT, collection.getCopyrightText(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_INTRODUCTORY_TEXT, collection.getIntroductoryText(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_SHORT_DESCRIPTION, collection.getShortDescription(), null);
|
||||
collectionService.setMetadataSingleValue(context, dspaceCollection,
|
||||
MD_SIDEBAR_TEXT, collection.getSidebarText(), null);
|
||||
collectionService.update(context, dspaceCollection);
|
||||
communityService.update(context, dspaceCommunity);
|
||||
retCollection = new Collection(dspaceCollection, servletContext, "", context, 100, 0);
|
||||
@@ -638,15 +648,16 @@ public class CommunitiesResource extends Resource {
|
||||
|
||||
org.dspace.content.Community dspaceCommunity = communityService
|
||||
.createSubcommunity(context, dspaceParentCommunity);
|
||||
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT,
|
||||
community.getCopyrightText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT,
|
||||
community.getIntroductoryText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION,
|
||||
community.getShortDescription());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT,
|
||||
community.getSidebarText());
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_NAME, community.getName(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_COPYRIGHT_TEXT, community.getCopyrightText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_INTRODUCTORY_TEXT, community.getIntroductoryText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SHORT_DESCRIPTION, community.getShortDescription(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SIDEBAR_TEXT, community.getSidebarText(), null);
|
||||
communityService.update(context, dspaceCommunity);
|
||||
communityService.update(context, dspaceParentCommunity);
|
||||
|
||||
@@ -718,15 +729,16 @@ public class CommunitiesResource extends Resource {
|
||||
headers, request, context);
|
||||
|
||||
// dspaceCommunity.setLogo(arg0); // TODO Add this option.
|
||||
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT,
|
||||
community.getCopyrightText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT,
|
||||
community.getIntroductoryText());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION,
|
||||
community.getShortDescription());
|
||||
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT,
|
||||
community.getSidebarText());
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_NAME, community.getName(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_COPYRIGHT_TEXT, community.getCopyrightText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_INTRODUCTORY_TEXT, community.getIntroductoryText(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SHORT_DESCRIPTION, community.getShortDescription(), null);
|
||||
communityService.setMetadataSingleValue(context, dspaceCommunity,
|
||||
MD_SIDEBAR_TEXT, community.getSidebarText(), null);
|
||||
communityService.update(context, dspaceCommunity);
|
||||
context.complete();
|
||||
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.rest.common;
|
||||
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_COPYRIGHT_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_INTRODUCTORY_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SHORT_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SIDEBAR_TEXT;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -28,7 +33,6 @@ import org.dspace.core.Context;
|
||||
* User: peterdietz
|
||||
* Date: 5/22/13
|
||||
* Time: 9:41 AM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@XmlRootElement(name = "collection")
|
||||
public class Collection extends DSpaceObject {
|
||||
@@ -41,9 +45,9 @@ public class Collection extends DSpaceObject {
|
||||
//Relationships
|
||||
private Bitstream logo;
|
||||
private Community parentCommunity;
|
||||
private List<Community> parentCommunityList = new ArrayList<Community>();
|
||||
private List<Community> parentCommunityList = new ArrayList<>();
|
||||
|
||||
private List<Item> items = new ArrayList<Item>();
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
//Collection-Metadata
|
||||
private String license;
|
||||
@@ -68,17 +72,19 @@ public class Collection extends DSpaceObject {
|
||||
private void setup(org.dspace.content.Collection collection, ServletContext servletContext, String expand,
|
||||
Context context, Integer limit, Integer offset)
|
||||
throws SQLException {
|
||||
List<String> expandFields = new ArrayList<String>();
|
||||
List<String> expandFields = new ArrayList<>();
|
||||
if (expand != null) {
|
||||
expandFields = Arrays.asList(expand.split(","));
|
||||
}
|
||||
|
||||
this.setCopyrightText(collectionService.getMetadata(collection, org.dspace.content.Collection.COPYRIGHT_TEXT));
|
||||
this.setIntroductoryText(
|
||||
collectionService.getMetadata(collection, org.dspace.content.Collection.INTRODUCTORY_TEXT));
|
||||
this.setShortDescription(
|
||||
collectionService.getMetadata(collection, org.dspace.content.Collection.SHORT_DESCRIPTION));
|
||||
this.setSidebarText(collectionService.getMetadata(collection, org.dspace.content.Collection.SIDEBAR_TEXT));
|
||||
this.setCopyrightText(collectionService.getMetadataFirstValue(collection,
|
||||
MD_COPYRIGHT_TEXT, org.dspace.content.Item.ANY));
|
||||
this.setIntroductoryText(collectionService.getMetadataFirstValue(collection,
|
||||
MD_INTRODUCTORY_TEXT, org.dspace.content.Item.ANY));
|
||||
this.setShortDescription(collectionService.getMetadataFirstValue(collection,
|
||||
MD_SHORT_DESCRIPTION, org.dspace.content.Item.ANY));
|
||||
this.setSidebarText(collectionService.getMetadataFirstValue(collection,
|
||||
MD_SIDEBAR_TEXT, org.dspace.content.Item.ANY));
|
||||
|
||||
if (expandFields.contains("parentCommunityList") || expandFields.contains("all")) {
|
||||
List<org.dspace.content.Community> parentCommunities = communityService.getAllParents(context, collection);
|
||||
@@ -104,7 +110,7 @@ public class Collection extends DSpaceObject {
|
||||
Iterator<org.dspace.content.Item> childItems =
|
||||
itemService.findByCollection(context, collection, limit, offset);
|
||||
|
||||
items = new ArrayList<Item>();
|
||||
items = new ArrayList<>();
|
||||
while (childItems.hasNext()) {
|
||||
org.dspace.content.Item item = childItems.next();
|
||||
|
||||
|
@@ -21,6 +21,10 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_COPYRIGHT_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_INTRODUCTORY_TEXT;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SHORT_DESCRIPTION;
|
||||
import static org.dspace.content.service.DSpaceObjectService.MD_SIDEBAR_TEXT;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
@@ -50,9 +54,9 @@ public class Community extends DSpaceObject {
|
||||
private String sidebarText;
|
||||
private Integer countItems;
|
||||
|
||||
private List<Community> subcommunities = new ArrayList<Community>();
|
||||
private List<Community> subcommunities = new ArrayList<>();
|
||||
|
||||
private List<Collection> collections = new ArrayList<Collection>();
|
||||
private List<Collection> collections = new ArrayList<>();
|
||||
|
||||
public Community() {
|
||||
}
|
||||
@@ -67,17 +71,19 @@ public class Community extends DSpaceObject {
|
||||
private void setup(org.dspace.content.Community community, ServletContext servletContext, String expand,
|
||||
Context context)
|
||||
throws SQLException {
|
||||
List<String> expandFields = new ArrayList<String>();
|
||||
List<String> expandFields = new ArrayList<>();
|
||||
if (expand != null) {
|
||||
expandFields = Arrays.asList(expand.split(","));
|
||||
}
|
||||
|
||||
this.setCopyrightText(communityService.getMetadata(community, org.dspace.content.Community.COPYRIGHT_TEXT));
|
||||
this.setIntroductoryText(
|
||||
communityService.getMetadata(community, org.dspace.content.Community.INTRODUCTORY_TEXT));
|
||||
this.setShortDescription(
|
||||
communityService.getMetadata(community, org.dspace.content.Community.SHORT_DESCRIPTION));
|
||||
this.setSidebarText(communityService.getMetadata(community, org.dspace.content.Community.SIDEBAR_TEXT));
|
||||
this.setCopyrightText(communityService.getMetadataFirstValue(community,
|
||||
MD_COPYRIGHT_TEXT, org.dspace.content.Item.ANY));
|
||||
this.setIntroductoryText(communityService.getMetadataFirstValue(community,
|
||||
MD_INTRODUCTORY_TEXT, org.dspace.content.Item.ANY));
|
||||
this.setShortDescription(communityService.getMetadataFirstValue(community,
|
||||
MD_SHORT_DESCRIPTION, org.dspace.content.Item.ANY));
|
||||
this.setSidebarText(communityService.getMetadataFirstValue(community,
|
||||
MD_SIDEBAR_TEXT, org.dspace.content.Item.ANY));
|
||||
this.setCountItems(itemService.countItems(context, community));
|
||||
|
||||
if (expandFields.contains("parentCommunity") || expandFields.contains("all")) {
|
||||
@@ -108,7 +114,7 @@ public class Community extends DSpaceObject {
|
||||
|
||||
if (expandFields.contains("subCommunities") || expandFields.contains("all")) {
|
||||
List<org.dspace.content.Community> communities = community.getSubcommunities();
|
||||
subcommunities = new ArrayList<Community>();
|
||||
subcommunities = new ArrayList<>();
|
||||
for (org.dspace.content.Community subCommunity : communities) {
|
||||
if (authorizeService.authorizeActionBoolean(context, subCommunity, org.dspace.core.Constants.READ)) {
|
||||
subcommunities.add(new Community(subCommunity, servletContext, null, context));
|
||||
|
@@ -134,7 +134,7 @@ authentication-shibboleth.lastname-header = SHIB-SURNAME
|
||||
# for each user. The left side is the Shibboleth-based metadata Header
|
||||
# and the right side is the eperson metadata field to map the attribute to.
|
||||
#authentication-shibboleth.eperson.metadata = \
|
||||
# SHIB-telephone => phone, \
|
||||
# SHIB-telephone => eperson.phone, \
|
||||
# SHIB-cn => cn
|
||||
|
||||
# If the eperson metadata field is not found, should it be automatically created?
|
||||
|
Reference in New Issue
Block a user