Search in sources :

Example 1 with EntrypointEntity

use of io.gravitee.rest.api.model.EntrypointEntity in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceImpl method update.

@Override
public EntrypointEntity update(final UpdateEntryPointEntity entrypointEntity, String referenceId, EntrypointReferenceType referenceType) {
    try {
        final Optional<Entrypoint> entrypointOptional = entrypointRepository.findByIdAndReference(entrypointEntity.getId(), referenceId, repoEntrypointReferenceType(referenceType));
        if (entrypointOptional.isPresent()) {
            final Entrypoint entrypoint = convert(entrypointEntity);
            Entrypoint existingEntrypoint = entrypointOptional.get();
            entrypoint.setReferenceId(existingEntrypoint.getReferenceId());
            entrypoint.setReferenceType(existingEntrypoint.getReferenceType());
            final EntrypointEntity savedEntryPoint = convert(entrypointRepository.update(entrypoint));
            auditService.createEnvironmentAuditLog(Collections.singletonMap(ENTRYPOINT, entrypoint.getId()), ENTRYPOINT_UPDATED, new Date(), entrypointOptional.get(), entrypoint);
            return savedEntryPoint;
        } else {
            throw new EntrypointNotFoundException(entrypointEntity.getId());
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to update entrypoint {}", entrypointEntity.getValue(), ex);
        throw new TechnicalManagementException("An error occurs while trying to update entrypoint " + entrypointEntity.getValue(), ex);
    }
}
Also used : EntrypointNotFoundException(io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Entrypoint(io.gravitee.repository.management.model.Entrypoint) EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with EntrypointEntity

use of io.gravitee.rest.api.model.EntrypointEntity in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceImpl method convert.

private EntrypointEntity convert(final Entrypoint entrypoint) {
    final EntrypointEntity entrypointEntity = new EntrypointEntity();
    entrypointEntity.setId(entrypoint.getId());
    entrypointEntity.setValue(entrypoint.getValue());
    entrypointEntity.setTags(entrypoint.getTags().split(SEPARATOR));
    return entrypointEntity;
}
Also used : EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity)

Example 3 with EntrypointEntity

use of io.gravitee.rest.api.model.EntrypointEntity in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceImpl method create.

@Override
public EntrypointEntity create(final NewEntryPointEntity entrypointEntity, String referenceId, EntrypointReferenceType referenceType) {
    try {
        final Entrypoint entrypoint = convert(entrypointEntity, referenceId, referenceType);
        final EntrypointEntity savedEntryPoint = convert(entrypointRepository.create(entrypoint));
        auditService.createEnvironmentAuditLog(Collections.singletonMap(ENTRYPOINT, entrypoint.getId()), ENTRYPOINT_CREATED, new Date(), null, entrypoint);
        return savedEntryPoint;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create entrypoint {}", entrypointEntity.getValue(), ex);
        throw new TechnicalManagementException("An error occurs while trying to create entrypoint " + entrypointEntity.getValue(), ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Entrypoint(io.gravitee.repository.management.model.Entrypoint) EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 4 with EntrypointEntity

use of io.gravitee.rest.api.model.EntrypointEntity in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceTest method shouldCreate.

@Test
public void shouldCreate() {
    final NewEntryPointEntity entrypoint = new NewEntryPointEntity();
    entrypoint.setValue(VALUE);
    entrypoint.setTags(TAGS);
    final EntrypointEntity entrypointEntity = entrypointService.create(entrypoint, REFERENCE_ID, REFERENCE_TYPE);
    assertEquals(ID, entrypointEntity.getId());
    assertEquals(VALUE, entrypointEntity.getValue());
    assertNotNull(entrypointEntity.getTags());
    assertEquals(2, entrypointEntity.getTags().length);
}
Also used : EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity) NewEntryPointEntity(io.gravitee.rest.api.model.NewEntryPointEntity) Test(org.junit.Test)

Example 5 with EntrypointEntity

use of io.gravitee.rest.api.model.EntrypointEntity in project gravitee-management-rest-api by gravitee-io.

the class EntrypointServiceTest method shouldUpdate.

@Test
public void shouldUpdate() {
    final UpdateEntryPointEntity entrypoint = new UpdateEntryPointEntity();
    entrypoint.setId(ID);
    entrypoint.setValue(NEW_VALUE);
    entrypoint.setTags(NEW_TAGS);
    final EntrypointEntity entrypointEntity = entrypointService.update(entrypoint, REFERENCE_ID, REFERENCE_TYPE);
    assertEquals(ID, entrypointEntity.getId());
    assertEquals(NEW_VALUE, entrypointEntity.getValue());
    assertNotNull(entrypointEntity.getTags());
    assertEquals(2, entrypointEntity.getTags().length);
}
Also used : UpdateEntryPointEntity(io.gravitee.rest.api.model.UpdateEntryPointEntity) EntrypointEntity(io.gravitee.rest.api.model.EntrypointEntity) Test(org.junit.Test)

Aggregations

EntrypointEntity (io.gravitee.rest.api.model.EntrypointEntity)6 Test (org.junit.Test)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Entrypoint (io.gravitee.repository.management.model.Entrypoint)2 UpdateEntryPointEntity (io.gravitee.rest.api.model.UpdateEntryPointEntity)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 NewEntryPointEntity (io.gravitee.rest.api.model.NewEntryPointEntity)1 EntrypointNotFoundException (io.gravitee.rest.api.service.exceptions.EntrypointNotFoundException)1