use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method findByName.
@Override
public List<GroupEntity> findByName(String name) {
try {
logger.debug("findByUsername : {}", name);
if (name == null) {
return Collections.emptyList();
}
List<GroupEntity> groupEntities = groupRepository.findAll().stream().filter(group -> group.getName().equals(name)).map(this::map).collect(Collectors.toList());
logger.debug("findByUsername : {} - DONE", name);
return groupEntities;
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to find groups by name", ex);
throw new TechnicalManagementException("An error occurs while trying to find groups by name", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method create.
@Override
public GroupEntity create(NewGroupEntity group) {
try {
logger.debug("create {}", group);
if (!this.findByName(group.getName()).isEmpty()) {
throw new GroupNameAlreadyExistsException(group.getName());
}
Group newGroup = this.map(group);
newGroup.setId(UUID.toString(UUID.random()));
newGroup.setCreatedAt(new Date());
newGroup.setUpdatedAt(newGroup.getCreatedAt());
GroupEntity grp = this.map(groupRepository.create(newGroup));
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(GROUP, newGroup.getId()), GROUP_CREATED, newGroup.getCreatedAt(), null, newGroup);
logger.debug("create {} - DONE", grp);
return grp;
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to create a group", ex);
throw new TechnicalManagementException("An error occurs while trying to create a group", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method update.
@Override
public MetadataEntity update(final UpdateMetadataEntity metadataEntity) {
try {
// First we prevent the duplicate metadata name
final Optional<Metadata> optionalMetadata = metadataRepository.findByReferenceType(MetadataReferenceType.DEFAULT).stream().filter(metadata -> !metadataEntity.getKey().equals(metadata.getKey()) && metadataEntity.getName().equalsIgnoreCase(metadata.getName())).findAny();
if (optionalMetadata.isPresent()) {
throw new DuplicateMetadataNameException(optionalMetadata.get().getName());
}
checkMetadataFormat(metadataEntity.getFormat(), metadataEntity.getValue());
final Metadata metadata = convert(metadataEntity);
final Date now = new Date();
metadata.setUpdatedAt(now);
metadataRepository.update(metadata);
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(METADATA, metadata.getKey()), METADATA_UPDATED, metadata.getCreatedAt(), null, metadata);
return convert(metadata);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to update metadata {}", metadataEntity.getName(), ex);
throw new TechnicalManagementException("An error occurred while trying to update metadata " + metadataEntity.getName(), ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method checkMetadataFormat.
@Override
public void checkMetadataFormat(final MetadataFormat format, final String value) {
if (isBlank(value)) {
return;
}
try {
switch(format) {
case BOOLEAN:
Boolean.valueOf(value);
break;
case URL:
new URL(value);
break;
case MAIL:
final InternetAddress email = new InternetAddress(value);
email.validate();
break;
case DATE:
final SimpleDateFormat sdf = new SimpleDateFormat("YYYY-mm-dd");
sdf.setLenient(false);
sdf.parse(value);
break;
case NUMERIC:
Double.valueOf(value);
break;
}
} catch (final Exception e) {
LOGGER.error("Error occurred while trying to validate format '{}' of value '{}'", format, value, e);
throw new TechnicalManagementException("Error occurred while trying to validate format " + format + " of value " + value, e);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method create.
@Override
public MetadataEntity create(final NewMetadataEntity metadataEntity) {
// if no format defined, we just set String format
if (metadataEntity.getFormat() == null) {
metadataEntity.setFormat(MetadataFormat.STRING);
}
try {
// First we prevent the duplicate metadata name
final Optional<MetadataEntity> optionalMetadata = findAllDefault().stream().filter(metadata -> metadataEntity.getName().equalsIgnoreCase(metadata.getName())).findAny();
if (optionalMetadata.isPresent()) {
throw new DuplicateMetadataNameException(optionalMetadata.get().getName());
}
checkMetadataFormat(metadataEntity.getFormat(), metadataEntity.getValue());
final Metadata metadata = convert(metadataEntity);
final Date now = new Date();
metadata.setCreatedAt(now);
metadata.setUpdatedAt(now);
metadataRepository.create(metadata);
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(METADATA, metadata.getKey()), METADATA_CREATED, metadata.getCreatedAt(), null, metadata);
return convert(metadata);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to create metadata {}", metadataEntity.getName(), ex);
throw new TechnicalManagementException("An error occurred while trying to create metadata " + metadataEntity.getName(), ex);
}
}
Aggregations