Search in sources :

Example 1 with ApplicationMetadataEntity

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;
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity)

Example 2 with 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());
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException) NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) ApplicationMetadataNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException) Before(org.junit.Before)

Example 3 with ApplicationMetadataEntity

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());
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) ReferenceMetadata(io.gravitee.rest.api.portal.rest.model.ReferenceMetadata) Test(org.junit.Test)

Example 4 with ApplicationMetadataEntity

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();
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 5 with ApplicationMetadataEntity

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();
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Aggregations

ApplicationMetadataEntity (io.gravitee.rest.api.model.ApplicationMetadataEntity)6 NewApplicationMetadataEntity (io.gravitee.rest.api.model.NewApplicationMetadataEntity)6 UpdateApplicationMetadataEntity (io.gravitee.rest.api.model.UpdateApplicationMetadataEntity)5 Test (org.junit.Test)2 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 ReferenceMetadata (io.gravitee.rest.api.portal.rest.model.ReferenceMetadata)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 ApplicationMetadataNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException)1 ApplicationNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException)1 Response (javax.ws.rs.core.Response)1 Before (org.junit.Before)1