@Test void testCopyEntity() throws Exception { @SuppressWarnings("unchecked") Repository<Entity> repositoryToCopy = mock(Repository.class); Package pack = mocksForCopyEntitySuccess(repositoryToCopy); String content = "{newEntityName: 'newEntity'}"; mockMvc .perform(post(HREF_COPY_ENTITY).content(content).contentType(APPLICATION_JSON)) .andExpect(status().isCreated()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(content().string("\"org_molgenis_blah_newEntity\"")) .andExpect(header().string("Location", "/api/v2/org_molgenis_blah_newEntity")); verify(repoCopier).copyRepository(repositoryToCopy, "newEntity", pack, "newEntity"); }
@Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) public String copyEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) { ServletUriComponentsBuilder uriBuilder = createUriBuilder(); if (!dataService.hasRepository(entityTypeId)) { throw new UnknownEntityTypeException(entityTypeId); } Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId); NameValidator.validateEntityName(request.getNewEntityName()); String newFullName = EntityTypeUtils.buildFullName( repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); if (dataService.hasRepository(newFullName)) { throw new RepositoryAlreadyExistsException(newFullName); } boolean readPermission = permissionService.hasPermission( new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA); if (!readPermission) { throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId); } boolean writableCapabilities = dataService .getCapabilities(repositoryToCopyFrom.getName()) .contains(RepositoryCapability.WRITABLE); if (!writableCapabilities) { throw new RepositoryNotCapableException( repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE); } Repository<Entity> repository = repoCopier.copyRepository( repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType()); response.addHeader( "Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName())); response.setStatus(HttpServletResponse.SC_CREATED); return repository.getName(); }
RestControllerV2 { @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) public String copyEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) { ServletUriComponentsBuilder uriBuilder = createUriBuilder(); if (!dataService.hasRepository(entityTypeId)) { throw new UnknownEntityTypeException(entityTypeId); } Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId); NameValidator.validateEntityName(request.getNewEntityName()); String newFullName = EntityTypeUtils.buildFullName( repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); if (dataService.hasRepository(newFullName)) { throw new RepositoryAlreadyExistsException(newFullName); } boolean readPermission = permissionService.hasPermission( new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA); if (!readPermission) { throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId); } boolean writableCapabilities = dataService .getCapabilities(repositoryToCopyFrom.getName()) .contains(RepositoryCapability.WRITABLE); if (!writableCapabilities) { throw new RepositoryNotCapableException( repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE); } Repository<Entity> repository = repoCopier.copyRepository( repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType()); response.addHeader( "Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName())); response.setStatus(HttpServletResponse.SC_CREATED); return repository.getName(); } }
RestControllerV2 { @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) public String copyEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) { ServletUriComponentsBuilder uriBuilder = createUriBuilder(); if (!dataService.hasRepository(entityTypeId)) { throw new UnknownEntityTypeException(entityTypeId); } Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId); NameValidator.validateEntityName(request.getNewEntityName()); String newFullName = EntityTypeUtils.buildFullName( repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); if (dataService.hasRepository(newFullName)) { throw new RepositoryAlreadyExistsException(newFullName); } boolean readPermission = permissionService.hasPermission( new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA); if (!readPermission) { throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId); } boolean writableCapabilities = dataService .getCapabilities(repositoryToCopyFrom.getName()) .contains(RepositoryCapability.WRITABLE); if (!writableCapabilities) { throw new RepositoryNotCapableException( repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE); } Repository<Entity> repository = repoCopier.copyRepository( repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType()); response.addHeader( "Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName())); response.setStatus(HttpServletResponse.SC_CREATED); return repository.getName(); } RestControllerV2(
      DataService dataService,
      UserPermissionEvaluator permissionService,
      RestService restService,
      LocalizationService localizationService,
      PermissionSystemService permissionSystemService,
      RepositoryCopier repoCopier); }
RestControllerV2 { @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) public String copyEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) { ServletUriComponentsBuilder uriBuilder = createUriBuilder(); if (!dataService.hasRepository(entityTypeId)) { throw new UnknownEntityTypeException(entityTypeId); } Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId); NameValidator.validateEntityName(request.getNewEntityName()); String newFullName = EntityTypeUtils.buildFullName( repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); if (dataService.hasRepository(newFullName)) { throw new RepositoryAlreadyExistsException(newFullName); } boolean readPermission = permissionService.hasPermission( new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA); if (!readPermission) { throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId); } boolean writableCapabilities = dataService .getCapabilities(repositoryToCopyFrom.getName()) .contains(RepositoryCapability.WRITABLE); if (!writableCapabilities) { throw new RepositoryNotCapableException( repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE); } Repository<Entity> repository = repoCopier.copyRepository( repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType()); response.addHeader( "Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName())); response.setStatus(HttpServletResponse.SC_CREATED); return repository.getName(); } RestControllerV2(
      DataService dataService,
      UserPermissionEvaluator permissionService,
      RestService restService,
      LocalizationService localizationService,
      PermissionSystemService permissionSystemService,
      RepositoryCopier repoCopier); @Autowired @Deprecated @Transactional(readOnly = true) @GetMapping("/version") Map<String, String> getVersion(
      @Value("${molgenis.version:@null}") String molgenisVersion,
      @Value("${molgenis.build.date:@null}") String molgenisBuildDate); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{id}") Map<String, Object> retrieveEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestParam(value = "attrs", required = false) AttributeFilter attributeFilter,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @PostMapping(value = "/{entityTypeId}/{id}", params = "_method=GET") Map<String, Object> retrieveEntityPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestParam(value = "attrs", required = false) AttributeFilter attributeFilter,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional @DeleteMapping("/{entityTypeId:^(?!i18n).+}/{id}") @ResponseStatus(NO_CONTENT) void deleteEntity(
      @PathVariable("entityTypeId") String entityTypeId, @PathVariable("id") String untypedId); @DeleteMapping("/{entityTypeId}") @ResponseStatus(NO_CONTENT) void deleteEntityCollection(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionDeleteRequestV2 request); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntityCollectionResponseV2 retrieveEntityCollection(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid EntityCollectionRequestV2 request,
      HttpServletRequest httpRequest,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @PostMapping(value = "/{entityTypeId}", params = "_method=GET") EntityCollectionResponseV2 retrieveEntityCollectionPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid EntityCollectionRequestV2 request,
      HttpServletRequest httpRequest,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @GetMapping(value = "/{entityTypeId}/meta/{attributeName}", produces = APPLICATION_JSON_VALUE) AttributeResponseV2 retrieveEntityAttributeMeta(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName); @Transactional(readOnly = true) @PostMapping( value = "/{entityTypeId}/meta/{attributeName}", params = "_method=GET", produces = APPLICATION_JSON_VALUE) AttributeResponseV2 retrieveEntityAttributeMetaPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PostMapping(value = "/{entityTypeId}", produces = APPLICATION_JSON_VALUE) EntityCollectionBatchCreateResponseBodyV2 createEntities(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) String copyEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid CopyEntityRequestV2 request,
      HttpServletResponse response); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PutMapping("/{entityTypeId}") synchronized void updateEntities(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional(readOnly = true) @GetMapping(value = "/i18n", produces = APPLICATION_JSON_VALUE) Map<String, String> getL10nStrings(); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PutMapping("/{entityTypeId}/{attributeName}") @ResponseStatus(OK) synchronized void updateAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional(readOnly = true) @GetMapping( value = "/i18n/{namespace}/{language}", produces = APPLICATION_JSON_VALUE + ";charset=UTF-8") Map<String, String> getL10nStrings(
      @PathVariable String namespace, @PathVariable String language); @Deprecated @Transactional(readOnly = true) @GetMapping( value = "/i18n/{namespace}_{language}.properties", produces = TEXT_PLAIN_VALUE + ";charset=UTF-8 ") String getL10nProperties(@PathVariable String namespace, @PathVariable String language); @Deprecated @Transactional @PostMapping("/i18n/{namespace}") @ResponseStatus(CREATED) void registerMissingResourceStrings(
      @PathVariable String namespace, HttpServletRequest request); @Deprecated @Transactional @DeleteMapping("/i18n/{namespace}") @ResponseStatus(NO_CONTENT) void deleteNamespace(@PathVariable String namespace); @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleHttpMessageNotReadableException(
      HttpMessageNotReadableException exception); @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleMethodArgumentNotValidException(
      MethodArgumentNotValidException exception); @ExceptionHandler(MolgenisDataException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleMolgenisDataException(MolgenisDataException e); @ExceptionHandler(MolgenisDataAccessException.class) @ResponseStatus(UNAUTHORIZED) @ResponseBody ErrorMessageResponse handleMolgenisDataAccessException(MolgenisDataAccessException e); @ExceptionHandler(ConversionFailedException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleConversionFailedException(ConversionFailedException e); }
RestControllerV2 { @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) public String copyEntity( @PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) { ServletUriComponentsBuilder uriBuilder = createUriBuilder(); if (!dataService.hasRepository(entityTypeId)) { throw new UnknownEntityTypeException(entityTypeId); } Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId); NameValidator.validateEntityName(request.getNewEntityName()); String newFullName = EntityTypeUtils.buildFullName( repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); if (dataService.hasRepository(newFullName)) { throw new RepositoryAlreadyExistsException(newFullName); } boolean readPermission = permissionService.hasPermission( new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA); if (!readPermission) { throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId); } boolean writableCapabilities = dataService .getCapabilities(repositoryToCopyFrom.getName()) .contains(RepositoryCapability.WRITABLE); if (!writableCapabilities) { throw new RepositoryNotCapableException( repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE); } Repository<Entity> repository = repoCopier.copyRepository( repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName()); permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType()); response.addHeader( "Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName())); response.setStatus(HttpServletResponse.SC_CREATED); return repository.getName(); } RestControllerV2(
      DataService dataService,
      UserPermissionEvaluator permissionService,
      RestService restService,
      LocalizationService localizationService,
      PermissionSystemService permissionSystemService,
      RepositoryCopier repoCopier); @Autowired @Deprecated @Transactional(readOnly = true) @GetMapping("/version") Map<String, String> getVersion(
      @Value("${molgenis.version:@null}") String molgenisVersion,
      @Value("${molgenis.build.date:@null}") String molgenisBuildDate); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}/{id}") Map<String, Object> retrieveEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestParam(value = "attrs", required = false) AttributeFilter attributeFilter,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @PostMapping(value = "/{entityTypeId}/{id}", params = "_method=GET") Map<String, Object> retrieveEntityPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestParam(value = "attrs", required = false) AttributeFilter attributeFilter,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional @DeleteMapping("/{entityTypeId:^(?!i18n).+}/{id}") @ResponseStatus(NO_CONTENT) void deleteEntity(
      @PathVariable("entityTypeId") String entityTypeId, @PathVariable("id") String untypedId); @DeleteMapping("/{entityTypeId}") @ResponseStatus(NO_CONTENT) void deleteEntityCollection(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionDeleteRequestV2 request); @Transactional(readOnly = true) @GetMapping("/{entityTypeId}") EntityCollectionResponseV2 retrieveEntityCollection(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid EntityCollectionRequestV2 request,
      HttpServletRequest httpRequest,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @PostMapping(value = "/{entityTypeId}", params = "_method=GET") EntityCollectionResponseV2 retrieveEntityCollectionPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid EntityCollectionRequestV2 request,
      HttpServletRequest httpRequest,
      @RequestParam(value = "includeCategories", defaultValue = "false")
          boolean includeCategories); @Transactional(readOnly = true) @GetMapping(value = "/{entityTypeId}/meta/{attributeName}", produces = APPLICATION_JSON_VALUE) AttributeResponseV2 retrieveEntityAttributeMeta(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName); @Transactional(readOnly = true) @PostMapping( value = "/{entityTypeId}/meta/{attributeName}", params = "_method=GET", produces = APPLICATION_JSON_VALUE) AttributeResponseV2 retrieveEntityAttributeMetaPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PostMapping(value = "/{entityTypeId}", produces = APPLICATION_JSON_VALUE) EntityCollectionBatchCreateResponseBodyV2 createEntities(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional @PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE) String copyEntity(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid CopyEntityRequestV2 request,
      HttpServletResponse response); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PutMapping("/{entityTypeId}") synchronized void updateEntities(
      @PathVariable("entityTypeId") String entityTypeId,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional(readOnly = true) @GetMapping(value = "/i18n", produces = APPLICATION_JSON_VALUE) Map<String, String> getL10nStrings(); @SuppressWarnings("java:S2259") // getEntities is guaranteed to be not empty @Transactional @PutMapping("/{entityTypeId}/{attributeName}") @ResponseStatus(OK) synchronized void updateAttribute(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response); @Deprecated @Transactional(readOnly = true) @GetMapping( value = "/i18n/{namespace}/{language}", produces = APPLICATION_JSON_VALUE + ";charset=UTF-8") Map<String, String> getL10nStrings(
      @PathVariable String namespace, @PathVariable String language); @Deprecated @Transactional(readOnly = true) @GetMapping( value = "/i18n/{namespace}_{language}.properties", produces = TEXT_PLAIN_VALUE + ";charset=UTF-8 ") String getL10nProperties(@PathVariable String namespace, @PathVariable String language); @Deprecated @Transactional @PostMapping("/i18n/{namespace}") @ResponseStatus(CREATED) void registerMissingResourceStrings(
      @PathVariable String namespace, HttpServletRequest request); @Deprecated @Transactional @DeleteMapping("/i18n/{namespace}") @ResponseStatus(NO_CONTENT) void deleteNamespace(@PathVariable String namespace); @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleHttpMessageNotReadableException(
      HttpMessageNotReadableException exception); @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleMethodArgumentNotValidException(
      MethodArgumentNotValidException exception); @ExceptionHandler(MolgenisDataException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleMolgenisDataException(MolgenisDataException e); @ExceptionHandler(MolgenisDataAccessException.class) @ResponseStatus(UNAUTHORIZED) @ResponseBody ErrorMessageResponse handleMolgenisDataAccessException(MolgenisDataAccessException e); @ExceptionHandler(ConversionFailedException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody ErrorMessageResponse handleConversionFailedException(ConversionFailedException e); static final String TIME_PARAM_NAME; }