Skip to content

Commit b6fee4d

Browse files
committed
fix to address issue: #10750
1 parent c55a68d commit b6fee4d

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.app.rest.converter;
9+
10+
import java.util.LinkedList;
11+
import java.util.List;
12+
13+
import org.apache.logging.log4j.Logger;
14+
import org.dspace.app.rest.model.SubmissionDefinitionRest;
15+
import org.dspace.app.rest.model.SubmissionSectionRest;
16+
import org.dspace.app.rest.projection.Projection;
17+
import org.dspace.app.rest.submit.DataProcessingStep;
18+
import org.dspace.app.util.SubmissionConfig;
19+
import org.dspace.app.util.SubmissionStepConfig;
20+
import org.dspace.services.RequestService;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.context.annotation.Lazy;
23+
import org.springframework.stereotype.Component;
24+
25+
/**
26+
* This is the converter from/to the SubmissionConfig in the DSpace API data
27+
* model and the REST data model
28+
*
29+
* @author Andrea Bollini (andrea.bollini at 4science.it)
30+
*/
31+
@Component
32+
public class SubmissionDefinitionConverter implements DSpaceConverter<SubmissionConfig, SubmissionDefinitionRest> {
33+
34+
private static final Logger log = org.apache.logging.log4j.LogManager
35+
.getLogger(SubmissionDefinitionConverter.class);
36+
37+
@Autowired
38+
private SubmissionSectionConverter panelConverter;
39+
40+
@Autowired
41+
private RequestService requestService;
42+
43+
// Must be loaded @Lazy, as ConverterService autowires all DSpaceConverter components
44+
@Lazy
45+
@Autowired
46+
private ConverterService converter;
47+
48+
@Override
49+
public SubmissionDefinitionRest convert(SubmissionConfig obj, Projection projection) {
50+
SubmissionDefinitionRest sd = new SubmissionDefinitionRest();
51+
sd.setProjection(projection);
52+
sd.setName(obj.getSubmissionName());
53+
sd.setDefaultConf(obj.isDefaultConf());
54+
List<SubmissionSectionRest> panels = new LinkedList<SubmissionSectionRest>();
55+
for (int idx = 0; idx < obj.getNumberOfSteps(); idx++) {
56+
SubmissionStepConfig step = obj.getStep(idx);
57+
try {
58+
// only the step that process data must be included in the panels list
59+
if (DataProcessingStep.class.isAssignableFrom(Class.forName(step.getProcessingClassName()))) {
60+
SubmissionSectionRest sp = converter.toRest(step, projection);
61+
panels.add(sp);
62+
}
63+
} catch (ClassNotFoundException e) {
64+
throw new IllegalStateException(
65+
"The submission configuration is invalid the processing class for the step " + step.getId()
66+
+ " is not found",
67+
e);
68+
}
69+
}
70+
sd.setPanels(panels);
71+
return sd;
72+
}
73+
74+
@Override
75+
public Class<SubmissionConfig> getModelClass() {
76+
return SubmissionConfig.class;
77+
}
78+
}

0 commit comments

Comments
 (0)