Skip to content

Commit

Permalink
Merge pull request DSpace#9241 from alexandrevryghem/w2p-108915_fix-l…
Browse files Browse the repository at this point in the history
…ink-repositories-using-singular-model_contribute-7.6

Fixed embedding data not working on model objects ending with an `s`
  • Loading branch information
tdonohue committed Feb 22, 2024
2 parents 422376d + a55d147 commit 42e3699
Show file tree
Hide file tree
Showing 254 changed files with 970 additions and 439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.dspace.app.rest;

import static org.dspace.app.rest.utils.RegexUtils.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID;

import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;
Expand Down Expand Up @@ -44,15 +46,9 @@
*/
@RestController
@RequestMapping("/api/" + CollectionRest.CATEGORY + "/" + CollectionRest.PLURAL_NAME
+ CollectionLogoController.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
public class CollectionLogoController {

/**
* Regular expression in the request mapping to accept UUID as identifier
*/
protected static final String REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID =
"/{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}";

@Autowired
protected Utils utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.dspace.app.rest;

import static org.dspace.app.rest.utils.RegexUtils.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID;

import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;
Expand Down Expand Up @@ -44,15 +46,9 @@
*/
@RestController
@RequestMapping("/api/" + CommunityRest.CATEGORY + "/" + CommunityRest.PLURAL_NAME
+ CommunityLogoController.REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/logo")
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID + "/" + CommunityRest.LOGO)
public class CommunityLogoController {

/**
* Regular expression in the request mapping to accept UUID as identifier
*/
protected static final String REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID =
"/{uuid:[0-9a-fxA-FX]{8}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{4}-[0-9a-fxA-FX]{12}}";

@Autowired
protected Utils utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Maria Verdonck (Atmire) on 2019-12-13
*/
@RestController
@RequestMapping("/api/" + EntityTypeRest.CATEGORY + "/" + EntityTypeRest.NAME_PLURAL)
@RequestMapping("/api/" + EntityTypeRest.CATEGORY + "/" + EntityTypeRest.PLURAL_NAME)
public class EntityTypeLabelRestController {

protected final EntityTypeService entityTypeService = ContentServiceFactory.getInstance().getEntityTypeService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* This will be the entry point for the api/eperson/groups endpoint with additional paths to it
*/
@RestController
@RequestMapping("/api/" + GroupRest.CATEGORY + "/" + GroupRest.GROUPS)
@RequestMapping("/api/" + GroupRest.CATEGORY + "/" + GroupRest.PLURAL_NAME)
public class GroupRestController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
* "/api/integration/qualityassuranceevents/{qaeventid}/related"
*/
@RestController
@RequestMapping("/api/" + QAEventRest.CATEGORY + "/qualityassuranceevents"
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG + "/related")
@RequestMapping("/api/" + QAEventRest.CATEGORY + "/" + QAEventRest.PLURAL_NAME
+ REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG + "/" + QAEventRest.RELATED)
public class QAEventRelatedRestController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.converter.JsonPatchConverter;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
Expand Down Expand Up @@ -126,7 +125,7 @@ public void afterPropertiesSet() {
// see https://github.com/spring-projects/spring-hateoas/issues/408
// Link l = linkTo(this.getClass(), r).withRel(r);
String[] split = r.split("\\.", 2);
String plural = English.plural(split[1]);
String plural = split[1];
Link l = Link.of("/api/" + split[0] + "/" + plural, plural);
links.add(l);
log.debug(l.getRel().value() + " " + l.getHref());
Expand Down Expand Up @@ -948,7 +947,7 @@ private <ID extends Serializable> RepresentationModel findRelInternal(HttpServle
int start = Math.toIntExact(page.getOffset());
int end = (start + page.getPageSize()) > fullList.size() ? fullList.size() : (start + page.getPageSize());
DSpaceRestRepository<RestAddressableModel, ?> resourceRepository = utils
.getResourceRepository(fullList.get(0).getCategory(), fullList.get(0).getType());
.getResourceRepository(fullList.get(0).getCategory(), fullList.get(0).getTypePlural());
PageImpl<RestAddressableModel> pageResult = new PageImpl(fullList.subList(start, end), page,
fullList.size());
return assembler.toModel(pageResult.map(converter::toResource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* It only supports a search method
*/

@Component(SubmissionCCLicenseUrlRest.CATEGORY + "." + SubmissionCCLicenseUrlRest.NAME)
@Component(SubmissionCCLicenseUrlRest.CATEGORY + "." + SubmissionCCLicenseUrlRest.PLURAL_NAME)
public class SubmissionCCLicenseUrlRepository extends DSpaceRestRepository<SubmissionCCLicenseUrlRest, String>
implements InitializingBean {

Expand Down Expand Up @@ -133,8 +133,8 @@ public Class<SubmissionCCLicenseUrlRest> getDomainClass() {
public void afterPropertiesSet() {
discoverableEndpointsService.register(this, Arrays.asList(
Link.of("/api/" + SubmissionCCLicenseUrlRest.CATEGORY + "/" +
SubmissionCCLicenseUrlRest.PLURAL + "/search",
SubmissionCCLicenseUrlRest.PLURAL + "-search")));
SubmissionCCLicenseUrlRest.PLURAL_NAME + "/search",
SubmissionCCLicenseUrlRest.PLURAL_NAME + "-search")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author Maria Verdonck (Atmire) on 11/12/2019
*/
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.NAME + "."
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.PLURAL_NAME + "."
+ WorkflowDefinitionRest.COLLECTIONS_MAPPED_TO)
public class WorkflowDefinitionCollectionsLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Maria Verdonck (Atmire) on 24/02/2020
*/
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.NAME + "."
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.PLURAL_NAME + "."
+ WorkflowDefinitionRest.STEPS)
public class WorkflowDefinitionStepsLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author Maria Verdonck (Atmire) on 24/02/2020
*/
@Component(WorkflowStepRest.CATEGORY + "." + WorkflowStepRest.NAME + "."
@Component(WorkflowStepRest.CATEGORY + "." + WorkflowStepRest.PLURAL_NAME + "."
+ WorkflowStepRest.ACTIONS)
public class WorkflowStepActionsLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.model.BaseObjectRest;
import org.dspace.app.rest.repository.DSpaceRestRepository;
import org.dspace.app.rest.repository.ReloadableEntityObjectRepository;
Expand Down Expand Up @@ -66,7 +67,8 @@ public BaseObjectRest getObject(Context context, String id) throws SQLException
String[] objType;
try {
objType = parts[2].split("\\.");
DSpaceRestRepository repository = utils.getResourceRepositoryByCategoryAndModel(objType[0], objType[1]);
DSpaceRestRepository repository = utils
.getResourceRepositoryByCategoryAndModel(objType[0], English.plural(objType[1]));
Serializable pk = utils.castToPKClass((ReloadableEntityObjectRepository) repository, objIdStr);
try {
// disable the security as we only need to retrieve the object to further process the authorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private String parseAnnotation(Annotation preAuthorize) {
private Annotation getAnnotationForRestObject(BaseObjectRest restObject) {
BaseObjectRest baseObjectRest = restObject;
DSpaceRestRepository repositoryToUse = utils
.getResourceRepositoryByCategoryAndModel(baseObjectRest.getCategory(), baseObjectRest.getType());
.getResourceRepositoryByCategoryAndModel(baseObjectRest.getCategory(), baseObjectRest.getTypePlural());
Annotation preAuthorize = null;
int maxDepth = 0;
// DS-4530 exclude the AOP Proxy from determining the annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.util.LinkedList;

import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.BrowseEntryRest;
import org.dspace.app.rest.model.BrowseIndexRest;
Expand All @@ -36,7 +35,7 @@ protected void addLinks(final BrowseEntryResource halResource, final Pageable pa

UriComponentsBuilder baseLink = uriBuilder(
getMethodOn(bix.getCategory(), bix.getType()).findRel(null, null, bix.getCategory(),
English.plural(bix.getType()), bix.getId(),
bix.getTypePlural(), bix.getId(),
BrowseIndexRest.LINK_ITEMS, null, null));

addFilterParams(baseLink, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.util.LinkedList;

import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.OrcidQueueRest;
Expand All @@ -37,15 +36,15 @@ protected void addLinks(OrcidQueueResource halResource, Pageable pageable, Linke
OrcidQueueRest orcidQueueRest = halResource.getContent();
if (orcidQueueRest.getProfileItemId() != null) {
UriComponentsBuilder uriComponentsBuilder = linkTo(getMethodOn(ItemRest.CATEGORY, ItemRest.NAME)
.findRel(null, null, ItemRest.CATEGORY, English.plural(ItemRest.NAME),
.findRel(null, null, ItemRest.CATEGORY, ItemRest.PLURAL_NAME,
orcidQueueRest.getProfileItemId(), "", null, null)).toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString();
list.add(buildLink("profileItem", uribuilder.substring(0, uribuilder.lastIndexOf("/"))));
}

if (orcidQueueRest.getEntityId() != null) {
UriComponentsBuilder uriComponentsBuilder = linkTo(getMethodOn(ItemRest.CATEGORY, ItemRest.NAME)
.findRel(null, null, ItemRest.CATEGORY, English.plural(ItemRest.NAME),
.findRel(null, null, ItemRest.CATEGORY, ItemRest.PLURAL_NAME,
orcidQueueRest.getEntityId(), "", null, null)).toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString();
list.add(buildLink("entity", uribuilder.substring(0, uribuilder.lastIndexOf("/"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.util.LinkedList;

import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.SubmissionAccessOptionRest;
import org.dspace.app.rest.model.SubmissionFormRest;
Expand All @@ -37,19 +36,22 @@ protected void addLinks(final SubmissionSectionResource halResource, final Pagea
SubmissionSectionRest sd = halResource.getContent();

if (SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(sd.getSectionType())) {
buildLink(list, sd, SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME);
buildLink(list, sd, SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME, SubmissionFormRest.PLURAL_NAME);
}
if (SubmissionStepConfig.UPLOAD_STEP_NAME.equals(sd.getSectionType())) {
buildLink(list, sd, SubmissionUploadRest.CATEGORY, SubmissionUploadRest.NAME);
buildLink(list, sd, SubmissionUploadRest.CATEGORY, SubmissionUploadRest.NAME,
SubmissionUploadRest.PLURAL_NAME);
}
if (SubmissionStepConfig.ACCESS_CONDITION_STEP_NAME.equals(sd.getSectionType())) {
buildLink(list, sd, SubmissionAccessOptionRest.CATEGORY, SubmissionAccessOptionRest.NAME);
buildLink(list, sd, SubmissionAccessOptionRest.CATEGORY, SubmissionAccessOptionRest.NAME,
SubmissionAccessOptionRest.PLURAL_NAME);
}
}

private void buildLink(final LinkedList<Link> list, SubmissionSectionRest sd, String category, String name) {
private void buildLink(final LinkedList<Link> list, SubmissionSectionRest sd, String category, String name,
String plural) {
UriComponentsBuilder uriComponentsBuilder = linkTo(getMethodOn(category, name)
.findRel(null, null, category, English.plural(name), sd.getId(), "", null, null))
.findRel(null, null, category, plural, sd.getId(), "", null, null))
.toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString();
list.add(buildLink(NAME_LINK_ON_PANEL, uribuilder.substring(0, uribuilder.lastIndexOf("/"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected void addLinks(SubmissionCCLicenseUrlResource halResource, final Pageab


UriComponentsBuilder uriComponentsBuilder = uriBuilder(getMethodOn().executeSearchMethods(
SubmissionCCLicenseUrlRest.CATEGORY, SubmissionCCLicenseUrlRest.PLURAL, "rightsByQuestions", null, null,
null, null, new LinkedMultiValueMap<>()));
SubmissionCCLicenseUrlRest.CATEGORY, SubmissionCCLicenseUrlRest.PLURAL_NAME, "rightsByQuestions", null,
null, null, null, new LinkedMultiValueMap<>()));
for (String key : parameterMap.keySet()) {
uriComponentsBuilder.queryParam(key, parameterMap.get(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.util.LinkedList;

import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.link.HalLinkFactory;
import org.dspace.app.rest.model.ItemRest;
Expand All @@ -29,10 +28,10 @@ protected void addLinks(RelationshipResource halResource, Pageable pageable, Lin
throws Exception {

list.add(buildLink("leftItem", getMethodOn()
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getLeftId())));
.findOne(ItemRest.CATEGORY, ItemRest.PLURAL_NAME, halResource.getContent().getLeftId())));

list.add(buildLink("rightItem", getMethodOn()
.findOne(ItemRest.CATEGORY, English.plural(ItemRest.NAME), halResource.getContent().getRightId())));
.findOne(ItemRest.CATEGORY, ItemRest.PLURAL_NAME, halResource.getContent().getRightId())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.dspace.app.rest.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

Expand All @@ -16,6 +15,7 @@
*/
public class AccessStatusRest implements RestModel {
public static final String NAME = "accessStatus";
public static final String PLURAL_NAME = NAME;

String status;

Expand All @@ -25,10 +25,12 @@ public String getType() {
return NAME;
}

/**
* The plural name is the same as the singular name
*/
@Override
@JsonIgnore
public String getTypePlural() {
return getType();
return PLURAL_NAME;
}

public AccessStatusRest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
public class AuthenticationTokenRest extends RestAddressableModel {
public static final String NAME = "shortlivedtoken";
public static final String PLURAL_NAME = "shortlivedtokens";
public static final String CATEGORY = RestAddressableModel.AUTHENTICATION;

private String token;
Expand All @@ -34,6 +35,11 @@ public String getType() {
return NAME;
}

@Override
public String getTypePlural() {
return PLURAL_NAME;
}

public String getToken() {
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class AuthnRest extends BaseObjectRest<Integer> {

public static final String NAME = "authn";
public static final String PLURAL_NAME = NAME;
public static final String CATEGORY = RestAddressableModel.AUTHENTICATION;

public String getCategory() {
Expand All @@ -28,6 +29,14 @@ public String getType() {
return NAME;
}

/**
* The plural name is the same as the singular name
*/
@Override
public String getTypePlural() {
return PLURAL_NAME;
}

public Class getController() {
return AuthenticationRestController.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
public class AuthorizationFeatureRest extends BaseObjectRest<String> {
public static final String NAME = "feature";
public static final String PLURAL_NAME = "features";
public static final String CATEGORY = RestAddressableModel.AUTHORIZATION;

private String description;
Expand All @@ -34,6 +35,11 @@ public String getType() {
return NAME;
}

@Override
public String getTypePlural() {
return PLURAL_NAME;
}

@Override
public String getCategory() {
return CATEGORY;
Expand Down
Loading

0 comments on commit 42e3699

Please sign in to comment.