mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
refactored AccessConditionConfigurationService
This commit is contained in:
@@ -6,7 +6,10 @@
|
|||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.submit.model;
|
package org.dspace.submit.model;
|
||||||
import java.util.Map;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple bean to manage different Access Condition configurations
|
* Simple bean to manage different Access Condition configurations
|
||||||
@@ -15,18 +18,11 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class AccessConditionConfigurationService {
|
public class AccessConditionConfigurationService {
|
||||||
|
|
||||||
/**
|
@Autowired
|
||||||
* Mapping the submission step process identifier with the configuration
|
private List<AccessConditionConfiguration> accessConditionConfigurations;
|
||||||
* (see configuration at access-conditions.xml)
|
|
||||||
*/
|
|
||||||
private Map<String, AccessConditionConfiguration> map;
|
|
||||||
|
|
||||||
public Map<String, AccessConditionConfiguration> getMap() {
|
public AccessConditionConfiguration getAccessConfigurationById(String name) {
|
||||||
return map;
|
return accessConditionConfigurations.stream().filter(x -> name.equals(x.getName())).findFirst().get();
|
||||||
}
|
|
||||||
|
|
||||||
public void setMap(Map<String, AccessConditionConfiguration> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -60,16 +60,10 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="accessConditionConfigurationService" class="org.dspace.submit.model.AccessConditionConfigurationService">
|
<bean id="accessConditionConfigurationService" class="org.dspace.submit.model.AccessConditionConfigurationService" />
|
||||||
<property name="map">
|
|
||||||
<map>
|
|
||||||
<entry key="defaultAC" value-ref="accessConditionConfigurationDefault" />
|
|
||||||
<entry key="notDiscoverable" value-ref="accessConditionConfigurationNotDiscoverable" />
|
|
||||||
</map>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="accessConditionConfigurationDefault" class="org.dspace.submit.model.AccessConditionConfiguration">
|
<bean id="accessConditionConfigurationDefault" class="org.dspace.submit.model.AccessConditionConfiguration">
|
||||||
|
<!-- This name must match the id of the step as defined in the item-submission.xml -->
|
||||||
<property name="name" value="defaultAC"></property>
|
<property name="name" value="defaultAC"></property>
|
||||||
<property name="canChangeDiscoverable" value="true"></property>
|
<property name="canChangeDiscoverable" value="true"></property>
|
||||||
<property name="options">
|
<property name="options">
|
||||||
@@ -82,6 +76,7 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="accessConditionConfigurationNotDiscoverable" class="org.dspace.submit.model.AccessConditionConfiguration">
|
<bean id="accessConditionConfigurationNotDiscoverable" class="org.dspace.submit.model.AccessConditionConfiguration">
|
||||||
|
<!-- This name must match the id of the step as defined in the item-submission.xml -->
|
||||||
<property name="name" value="notDiscoverable"></property>
|
<property name="name" value="notDiscoverable"></property>
|
||||||
<property name="canChangeDiscoverable" value="false"></property>
|
<property name="canChangeDiscoverable" value="false"></property>
|
||||||
<property name="options">
|
<property name="options">
|
||||||
|
@@ -34,7 +34,7 @@ public class SubmissionAccessOptionRestRepository extends DSpaceRestRepository<S
|
|||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
public SubmissionAccessOptionRest findOne(Context context, String id) {
|
public SubmissionAccessOptionRest findOne(Context context, String id) {
|
||||||
AccessConditionConfiguration configuration = accessConditionConfigurationService.getMap().get(id);
|
AccessConditionConfiguration configuration = accessConditionConfigurationService.getAccessConfigurationById(id);
|
||||||
return Objects.nonNull(configuration) ? converter.toRest(configuration, utils.obtainProjection()) : null;
|
return Objects.nonNull(configuration) ? converter.toRest(configuration, utils.obtainProjection()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,8 @@ public class AccessConditionAddPatchOperation extends AddPatchOperation<AccessCo
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
||||||
AccessConditionConfiguration configuration = accessConditionConfigurationService.getMap().get(stepId);
|
AccessConditionConfiguration configuration = accessConditionConfigurationService
|
||||||
|
.getAccessConfigurationById(stepId);
|
||||||
|
|
||||||
Item item = source.getItem();
|
Item item = source.getItem();
|
||||||
|
|
||||||
|
@@ -33,7 +33,8 @@ public class AccessConditionDiscoverableReplacePatchOperation extends ReplacePat
|
|||||||
Object value) throws Exception {
|
Object value) throws Exception {
|
||||||
|
|
||||||
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
||||||
AccessConditionConfiguration configuration = accessConditionConfigurationService.getMap().get(stepId);
|
AccessConditionConfiguration configuration = accessConditionConfigurationService
|
||||||
|
.getAccessConfigurationById(stepId);
|
||||||
|
|
||||||
if (Objects.isNull(configuration) || !configuration.getCanChangeDiscoverable().booleanValue()) {
|
if (Objects.isNull(configuration) || !configuration.getCanChangeDiscoverable().booleanValue()) {
|
||||||
throw new UnprocessableEntityException("The current access configurations does not allow" +
|
throw new UnprocessableEntityException("The current access configurations does not allow" +
|
||||||
|
@@ -52,7 +52,8 @@ public class AccessConditionReplacePatchOperation extends ReplacePatchOperation<
|
|||||||
Object value) throws Exception {
|
Object value) throws Exception {
|
||||||
|
|
||||||
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
||||||
AccessConditionConfiguration configuration = accessConditionConfigurationService.getMap().get(stepId);
|
AccessConditionConfiguration configuration = accessConditionConfigurationService
|
||||||
|
.getAccessConfigurationById(stepId);
|
||||||
|
|
||||||
// "path" : "/sections/<:name-of-the-form>/accessConditions/0/name"
|
// "path" : "/sections/<:name-of-the-form>/accessConditions/0/name"
|
||||||
// the absolutePath will be : accessConditions/0 or accessConditions/0/name
|
// the absolutePath will be : accessConditions/0 or accessConditions/0/name
|
||||||
|
@@ -61,15 +61,10 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="accessConditionConfigurationService" class="org.dspace.submit.model.AccessConditionConfigurationService">
|
<bean id="accessConditionConfigurationService" class="org.dspace.submit.model.AccessConditionConfigurationService" />
|
||||||
<property name="map">
|
|
||||||
<map>
|
|
||||||
<entry key="itemAccessConditions" value-ref="accessConditionConfigurationDefault" />
|
|
||||||
</map>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="accessConditionConfigurationDefault" class="org.dspace.submit.model.AccessConditionConfiguration">
|
<bean id="accessConditionConfigurationDefault" class="org.dspace.submit.model.AccessConditionConfiguration">
|
||||||
|
<!-- This name must match the id of the step as defined in the item-submission.xml -->
|
||||||
<property name="name" value="itemAccessConditions"></property>
|
<property name="name" value="itemAccessConditions"></property>
|
||||||
<property name="canChangeDiscoverable" value="true"></property>
|
<property name="canChangeDiscoverable" value="true"></property>
|
||||||
<property name="options">
|
<property name="options">
|
||||||
|
Reference in New Issue
Block a user