use of io.gravitee.rest.api.model.ApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataServiceImpl method convert.
private ApplicationMetadataEntity convert(ReferenceMetadataEntity m, String applicationId) {
final ApplicationMetadataEntity applicationMetadataEntity = new ApplicationMetadataEntity();
applicationMetadataEntity.setKey(m.getKey());
applicationMetadataEntity.setName(m.getName());
applicationMetadataEntity.setFormat(m.getFormat());
applicationMetadataEntity.setValue(m.getValue());
applicationMetadataEntity.setDefaultValue(m.getDefaultValue());
applicationMetadataEntity.setApplicationId(applicationId);
return applicationMetadataEntity;
}
use of io.gravitee.rest.api.model.ApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResourceTest method init.
@Before
public void init() {
resetAllMocks();
ApplicationMetadataEntity applicationMetadataEntity1 = new ApplicationMetadataEntity();
applicationMetadataEntity1.setKey(METADATA_1);
ApplicationMetadataEntity applicationMetadataEntity2 = new ApplicationMetadataEntity();
applicationMetadataEntity2.setKey(METADATA_2);
when(referenceMetadataMapper.convert(any())).thenCallRealMethod();
when(referenceMetadataMapper.convert(any(), any())).thenCallRealMethod();
when(referenceMetadataMapper.convert(any(), any(), any())).thenCallRealMethod();
doReturn(Arrays.asList(applicationMetadataEntity1, applicationMetadataEntity2)).when(applicationMetadataService).findAllByApplication(APPLICATION);
doReturn(applicationMetadataEntity1).when(applicationMetadataService).findByIdAndApplication(METADATA_1, APPLICATION);
doReturn(null).when(applicationMetadataService).findByIdAndApplication(METADATA_2, APPLICATION);
when(applicationMetadataService.create(any())).thenAnswer(invocation -> {
NewApplicationMetadataEntity newApplicationMetadataEntity = invocation.getArgument(0);
if (newApplicationMetadataEntity.getApplicationId().equals(UNKNOWN_APPLICATION)) {
throw new ApplicationNotFoundException(UNKNOWN_APPLICATION);
}
return applicationMetadataEntity1;
});
when(applicationMetadataService.update(any())).thenAnswer(invocation -> {
UpdateApplicationMetadataEntity updateApplicationMetadataEntity = invocation.getArgument(0);
if (updateApplicationMetadataEntity.getApplicationId().equals(UNKNOWN_APPLICATION)) {
throw new ApplicationNotFoundException(UNKNOWN_APPLICATION);
}
if (updateApplicationMetadataEntity.getKey().equals(UNKNOWN_METADATA)) {
throw new ApplicationMetadataNotFoundException(updateApplicationMetadataEntity.getApplicationId(), UNKNOWN_METADATA);
}
return applicationMetadataEntity1;
});
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).findAllByApplication(UNKNOWN_APPLICATION);
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).findByIdAndApplication(any(), eq(UNKNOWN_APPLICATION));
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).delete(any(), eq(UNKNOWN_APPLICATION));
doThrow(ApplicationMetadataNotFoundException.class).when(applicationMetadataService).findByIdAndApplication(UNKNOWN_METADATA, APPLICATION);
doThrow(ApplicationMetadataNotFoundException.class).when(applicationMetadataService).delete(eq(UNKNOWN_METADATA), any());
}
use of io.gravitee.rest.api.model.ApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ReferenceMetadataMapperTest method testConvertEntityToPojo.
@Test
public void testConvertEntityToPojo() {
// init
ApplicationMetadataEntity applicationMetadataEntity = new ApplicationMetadataEntity();
applicationMetadataEntity.setApplicationId(METADATA_APPLICATION_ID);
applicationMetadataEntity.setDefaultValue(METADATA_DEFAULT_VALUE);
applicationMetadataEntity.setValue(METADATA_VALUE);
applicationMetadataEntity.setFormat(MetadataFormat.valueOf(METADATA_FORMAT));
applicationMetadataEntity.setKey(METADATA_KEY);
applicationMetadataEntity.setName(METADATA_NAME);
// Test
final ReferenceMetadata referenceMetadata = referenceMetadataMapper.convert(applicationMetadataEntity);
assertNotNull(referenceMetadata);
assertEquals(METADATA_APPLICATION_ID, referenceMetadata.getApplication());
assertEquals(METADATA_DEFAULT_VALUE, referenceMetadata.getDefaultValue());
assertEquals(METADATA_KEY, referenceMetadata.getKey());
assertEquals(METADATA_NAME, referenceMetadata.getName());
assertEquals(METADATA_VALUE, referenceMetadata.getValue());
assertEquals(ReferenceMetadataFormatType.valueOf(METADATA_FORMAT), referenceMetadata.getFormat());
}
use of io.gravitee.rest.api.model.ApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResource method createApplicationMetadata.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApplicationMetadata(@PathParam("applicationId") String applicationId, @Valid @NotNull final ReferenceMetadataInput metadata) {
// prevent creation of a metadata on an another APPLICATION
NewApplicationMetadataEntity newApplicationMetadataEntity = this.referenceMetadataMapper.convert(metadata, applicationId);
final ApplicationMetadataEntity applicationMetadataEntity = metadataService.create(newApplicationMetadataEntity);
return Response.created(this.getLocationHeader(applicationMetadataEntity.getKey())).entity(this.referenceMetadataMapper.convert(applicationMetadataEntity)).build();
}
use of io.gravitee.rest.api.model.ApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResource method createApplicationMetadata.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an application metadata", notes = "User must have the APPLICATION_METADATA[CREATE] permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Application metadata successfully created", response = ApplicationMetadataEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApplicationMetadata(@Valid @NotNull final NewApplicationMetadataEntity metadata) {
// prevent creation of a metadata on an another APPLICATION
metadata.setApplicationId(application);
final ApplicationMetadataEntity applicationMetadataEntity = metadataService.create(metadata);
return Response.created(this.getLocationHeader(applicationMetadataEntity.getKey())).entity(applicationMetadataEntity).build();
}
Aggregations