All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tno.bim.nmd.controller.ProductCardController Maven / Gradle / Ivy

The newest version!
package nl.tno.bim.nmd.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import nl.tno.bim.nmd.domain.NmdProductCard;

@CrossOrigin()
@RestController()
@RequestMapping(value = "/api")
public class ProductCardController extends BaseNMDController {
	
	public ProductCardController() {
		super();
	}
	
    @ApiOperation(value = "Get ProductCard(s) By Product card Ids ")
    @RequestMapping(method = RequestMethod.GET, value = "/{versionId}/productcard/{ids}")
    public ResponseEntity> getProductCardByIds(
    		@PathVariable Integer versionId,
    		@PathVariable String ids) {
    	
        logMessage("triggering method getProductCardByIds");
        List elIds = new ArrayList<>();
        String[] sIds = ids.split(",");
        for (String id : sIds) {
        	elIds.add(Long.parseLong(id));
        }
        
        List pcs = getService(versionId).getProductCardsByIds(elIds);
        if (pcs == null || pcs.isEmpty()) {
        	logMessage("returning 404: no data found ");
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }

        // load the profile sets if not already loaded
        pcs.forEach(pc -> getService(versionId).getAdditionalProfileDataForCard(pc));

        logMessage("returning 200: ProductCard(s) found");
        
        return ResponseEntity.status(HttpStatus.OK).body(pcs);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy