Project

General

Profile

Revision ebbad310

IDebbad31065fbf01ed7bfcf2179e477ace2081051
Parent 086d2a44
Child c22a678f

Added by Andreas Kohlbecker 7 months ago

ref #7927 /registration/identifier/**/status web service implemented

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/RegistrationController.java
11 11

  
12 12
import java.io.IOException;
13 13
import java.util.Arrays;
14
import java.util.Map;
14 15
import java.util.UUID;
15 16

  
16 17
import javax.servlet.http.HttpServletRequest;
......
23 24
import org.springframework.web.bind.annotation.RequestMapping;
24 25
import org.springframework.web.bind.annotation.RequestMethod;
25 26
import org.springframework.web.bind.annotation.RequestParam;
27
import org.springframework.web.servlet.ModelAndView;
26 28

  
27 29
import eu.etaxonomy.cdm.api.service.IRegistrationService;
28 30
import eu.etaxonomy.cdm.api.service.pager.Pager;
......
111 113
        }
112 114
    }
113 115

  
116
    @ApiImplicitParams({
117
        @ApiImplicitParam(name = "identifier", value = "The persitent identifier of the Registration.", required = true, dataType = "string", paramType = "path"),
118
    })
119
    @ApiOperation(value = "Finds status of a Registration by persitent identifier.",
120
        notes = "The identifier passed as paramter must be unique in the database otherwise the server will responde with the HTTP error code: " + HttpServletResponse.SC_PRECONDITION_FAILED
121
    )
122
    @RequestMapping(value="identifier/**/status", method = RequestMethod.GET)
123
    public ModelAndView doStatusByIdentifier(
124
            HttpServletRequest request,
125
            HttpServletResponse response) throws IOException {
126

  
127
        logger.info("doStatusByIdentifier() " + requestPathAndQuery(request));
128

  
129
        String identifier = readPathParameter(request, "/registration/identifier/");
130
        identifier = identifier.replace("/status", "");
131

  
132
        Map<UUID, RegistrationStatus> map = service.statusByIdentifier(identifier);
133

  
134
        ModelAndView mv = new ModelAndView();
135

  
136
        if(map.size() == 1){
137
            String status = map.values().iterator().next().name();
138
            mv.addObject(status);
139
            return mv;
140
        } else if(map.size() > 1){
141
            HttpStatusMessage.create("The identifier " + identifier + " refrences multiple registrations", HttpServletResponse.SC_PRECONDITION_FAILED).send(response);
142
            return mv; // never reached, due to previous send()
143
        } else {
144
            return mv;
145
        }
146
    }
147

  
114 148

  
115 149
    @ApiImplicitParams({
116 150
        @ApiImplicitParam(name = "identifier", value = "The persitent identifier of the Registration", required = true, dataType = "string", paramType = "path"),
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/RegistrationDTOController.java
115 115

  
116 116
        Pager<RegistrationDTO> regPager = registrationWorkingSetService.pageDTOs(identifier, 0, 2);
117 117

  
118
        if(regPager.getCount() > 0){
118
        if(regPager.getCount() == 1){
119 119
            return regPager.getRecords().get(0);
120
        } else if(regPager.getCount() > 1){
121
            HttpStatusMessage.create("The identifier " + identifier + " refrences multiple registrations", HttpServletResponse.SC_PRECONDITION_FAILED).send(response);
122
            return null; // never reached, due to previous send()
120 123
        } else {
121 124
            return null;
122 125
        }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IRegistrationService.java
11 11
import java.io.IOException;
12 12
import java.util.Collection;
13 13
import java.util.List;
14
import java.util.Map;
14 15
import java.util.Optional;
15 16
import java.util.Set;
16 17
import java.util.UUID;
......
119 120

  
120 121
    Pager<Registration> pageByIdentifier(String identifier, Integer pageIndex, Integer pageSize, List<String> propertyPaths) throws IOException;
121 122

  
123
    public Map<UUID, RegistrationStatus> statusByIdentifier(String identifier) throws IOException;
124

  
122 125
    /**
123 126
     * @param submitterUuid
124 127
     * @param includedStatusUuids
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/RegistrationServiceImpl.java
262 262
        return regPager;
263 263
    }
264 264

  
265
    @Override
266
    @Transactional(readOnly = true)
267
    public Map<UUID, RegistrationStatus> statusByIdentifier(String identifier) throws IOException {
268

  
269
        Pager<Registration> regPager = pageByRestrictions(Registration.class, "identifier", identifier, MatchMode.EXACT,
270
                null, null, null, null, Arrays.asList("status"));
271

  
272
        Map<UUID, RegistrationStatus> map = new HashMap<>();
273
        for(Registration reg : regPager.getRecords()){
274
            map.put(reg.getUuid(), reg.getStatus());
275
        }
276

  
277
        return map;
278
    }
279

  
265 280
    /**
266 281
     * {@inheritDoc}
267 282
     */

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)