Skip to content

Commit

Permalink
Merge pull request #27 from nimble-platform/staging
Browse files Browse the repository at this point in the history
Pull Request for Release MVP 19.0.1 / FMP 13.0.1
  • Loading branch information
dogukan10 authored Oct 8, 2020
2 parents c73411c + 2e64090 commit 4e20bd1
Showing 1 changed file with 73 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
package eu.nimble.indexing.web.controller;

import java.util.List;

import eu.nimble.indexing.service.IdentityService;
import eu.nimble.service.model.solr.owl.ClassType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static eu.nimble.indexing.utils.OpenIdConnectUserDetails.Role.*;

import eu.nimble.indexing.service.ItemService;
import eu.nimble.service.model.solr.item.ItemType;
/**
* Controller for managing catalogs. Supports
* <ul>
* <li>bulk uploading of items belonging to a single catalogue
* <li>deletion of all items in the given catalogue
* </ul>
* @author dglachs
*
*/
@RestController
@Api(value = "Catalogue Controller",
description = "Catalogue API to index and delete catalogues (list of items)")
public class CatalogueController {

@Autowired
private IdentityService identityService;

@Autowired
private ItemService items;

@ApiOperation(value = "", notes = "Delete all items in a catalogue", response = Long.class)
@DeleteMapping("/catalogue")
public ResponseEntity<?> deleteCatalogue(
@RequestHeader(value = "Authorization") String bearerToken,
@RequestParam(value="catalogueId") String catalogueId
) throws Exception{

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE, PUBLISHER
,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Access The Indexing End Points",
HttpStatus.UNAUTHORIZED);

return ResponseEntity.ok(items.deleteCatalogue(catalogueId));
}

@ApiOperation(value = "", notes = "Index a list of items", response = Boolean.class)
@PostMapping("/catalogue")
public ResponseEntity<?> postCatalogue(
@RequestHeader(value = "Authorization") String bearerToken,
@RequestParam(value="catalogueId") String catalogueId,
@RequestBody List<ItemType> catalogueItems) {

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE, PUBLISHER
,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Access The Indexing End Points",
HttpStatus.UNAUTHORIZED);

return ResponseEntity.ok(items.set(catalogueItems));
}
}
package eu.nimble.indexing.web.controller;

import java.util.List;

import eu.nimble.indexing.service.IdentityService;
import eu.nimble.service.model.solr.owl.ClassType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static eu.nimble.indexing.utils.OpenIdConnectUserDetails.Role.*;

import eu.nimble.indexing.service.ItemService;
import eu.nimble.service.model.solr.item.ItemType;
/**
* Controller for managing catalogs. Supports
* <ul>
* <li>bulk uploading of items belonging to a single catalogue
* <li>deletion of all items in the given catalogue
* </ul>
* @author dglachs
*
*/
@RestController
@Api(value = "Catalogue Controller",
description = "Catalogue API to index and delete catalogues (list of items)")
public class CatalogueController {

@Autowired
private IdentityService identityService;

@Autowired
private ItemService items;

@ApiOperation(value = "", notes = "Delete all items in a catalogue", response = Long.class)
@DeleteMapping("/catalogue")
public ResponseEntity<?> deleteCatalogue(
@RequestHeader(value = "Authorization") String bearerToken,
@RequestParam(value="catalogueId") String catalogueId
) throws Exception{

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE, PUBLISHER
,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Access The Indexing End Points",
HttpStatus.UNAUTHORIZED);

return ResponseEntity.ok(items.deleteCatalogue(catalogueId));
}

@ApiOperation(value = "", notes = "Index a list of items", response = Boolean.class)
@PostMapping("/catalogue")
public ResponseEntity<?> postCatalogue(
@RequestHeader(value = "Authorization") String bearerToken,
@RequestParam(value="catalogueId") String catalogueId,
@RequestBody List<ItemType> catalogueItems) {

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE, PUBLISHER
,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Access The Indexing End Points",
HttpStatus.UNAUTHORIZED);
// delete the items belonging to the given catalogue
items.deleteCatalogue(catalogueId);
// index the catalogue items
return ResponseEntity.ok(items.set(catalogueItems));
}
}

0 comments on commit 4e20bd1

Please sign in to comment.