use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method create.
@Override
public PageRevisionEntity create(Page page) {
try {
logger.debug("Create page revision for page {}", page.getId());
PageType type = PageType.valueOf(page.getType());
if (!(type == PageType.MARKDOWN || type == PageType.SWAGGER || type == PageType.TRANSLATION)) {
throw new TechnicalManagementException("Invalid page type for revision");
}
PageRevision revision = pageRevisionRepository.create(convert(page));
return convert(revision);
} catch (TechnicalException e) {
logger.warn("An error occurs while trying to create a revision for page {}", page.getId(), e);
throw new TechnicalManagementException("An error occurs while trying to create a page revision", e);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageRevisionServiceImpl method findAll.
@Override
public io.gravitee.common.data.domain.Page<PageRevisionEntity> findAll(Pageable pageable) {
logger.debug("get all page revisions with pageable {}", pageable);
try {
io.gravitee.common.data.domain.Page<PageRevision> revisions = pageRevisionRepository.findAll(pageable);
List<PageRevisionEntity> revisionEntities = revisions.getContent().stream().map(this::convert).collect(Collectors.toList());
return new io.gravitee.common.data.domain.Page<PageRevisionEntity>(revisionEntities, revisions.getPageNumber(), revisionEntities.size(), revisions.getTotalElements());
} catch (TechnicalException e) {
logger.warn("An error occurs while trying to get the page revisions {}", pageable, e);
throw new TechnicalManagementException("An error occurs while trying to get all page revisions", e);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method findAll.
@Override
public <T> List<T> findAll(final Key key, final Function<String, T> mapper, final Predicate<String> filter, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
try {
Optional<Parameter> optionalParameter = this.getSystemParameter(key);
if (optionalParameter.isPresent()) {
return splitValue(optionalParameter.get().getValue(), mapper, filter);
}
switch(referenceType) {
case ENVIRONMENT:
optionalParameter = this.getEnvParameter(key, refIdToUse);
if (optionalParameter.isPresent()) {
return splitValue(optionalParameter.get().getValue(), mapper, filter);
}
// String organizationId = "DEFAULT";
String organizationId = environmentService.findById(refIdToUse).getOrganizationId();
optionalParameter = this.getOrgParameter(key, organizationId);
if (optionalParameter.isPresent()) {
return splitValue(optionalParameter.get().getValue(), mapper, filter);
}
case ORGANIZATION:
optionalParameter = this.getOrgParameter(key, refIdToUse);
if (optionalParameter.isPresent()) {
return splitValue(optionalParameter.get().getValue(), mapper, filter);
}
}
return splitValue(this.getDefaultParameterValue(key), mapper, filter);
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to find parameter values with key: " + key;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method save.
@Override
public Parameter save(final Key key, final String value, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
try {
Optional<Parameter> optionalParameter = parameterRepository.findById(key.key(), refIdToUse, ParameterReferenceType.valueOf(referenceType.name()));
final boolean updateMode = optionalParameter.isPresent();
final Parameter parameter = new Parameter();
parameter.setKey(key.key());
parameter.setReferenceId(refIdToUse);
parameter.setReferenceType(ParameterReferenceType.valueOf(referenceType.name()));
parameter.setValue(value);
if (environment.containsProperty(key.key()) && key.isOverridable()) {
parameter.setValue(toSemicolonSeparatedString(key, environment.getProperty(key.key())));
return parameter;
}
if (updateMode) {
if (value == null) {
parameterRepository.delete(key.key(), refIdToUse, ParameterReferenceType.valueOf(referenceType.name()));
return null;
} else if (!value.equals(optionalParameter.get().getValue())) {
final Parameter updatedParameter = parameterRepository.update(parameter);
auditService.createEnvironmentAuditLog(singletonMap(PARAMETER, updatedParameter.getKey()), PARAMETER_UPDATED, new Date(), optionalParameter.get(), updatedParameter);
eventManager.publishEvent(key, parameter);
return updatedParameter;
} else {
return optionalParameter.get();
}
} else {
if (value == null) {
return null;
}
final Parameter savedParameter = parameterRepository.create(parameter);
auditService.createEnvironmentAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
eventManager.publishEvent(key, parameter);
return savedParameter;
}
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to create parameter for key/value: " + key + '/' + value;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method findAll.
@Override
public <T> Map<String, List<T>> findAll(List<Key> keys, Function<String, T> mapper, Predicate<String> filter, final String referenceId, final io.gravitee.rest.api.model.parameters.ParameterReferenceType referenceType) {
String refIdToUse = getEffectiveReferenceId(referenceId, referenceType);
try {
List<Key> keysToFind = new ArrayList<>(keys);
Map<String, List<T>> result = new HashMap<>();
// Get System parameters
for (Key keyToFind : keys) {
this.getSystemParameter(keyToFind).ifPresent(p -> {
result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
keysToFind.remove(keyToFind);
});
}
if (!keysToFind.isEmpty()) {
switch(referenceType) {
case ENVIRONMENT:
this.getEnvParameters(keysToFind, refIdToUse).forEach(p -> {
result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
keysToFind.remove(Key.findByKey(p.getKey()));
});
if (!keysToFind.isEmpty()) {
// String organizationId = "DEFAULT";//environmentService.findById(referenceId).getOrganizationId();
String organizationId = environmentService.findById(refIdToUse).getOrganizationId();
this.getOrgParameters(keysToFind, organizationId).forEach(p -> {
result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
keysToFind.remove(Key.findByKey(p.getKey()));
});
if (!keysToFind.isEmpty()) {
keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
}
}
break;
case ORGANIZATION:
this.getOrgParameters(keysToFind, refIdToUse).forEach(p -> {
result.put(p.getKey(), splitValue(p.getValue(), mapper, filter));
keysToFind.remove(Key.findByKey(p.getKey()));
});
if (!keysToFind.isEmpty()) {
keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
}
break;
default:
keysToFind.forEach(k -> result.put(k.key(), splitValue(k.defaultValue(), mapper, filter)));
break;
}
}
return result;
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to find parameter values with keys: " + keys;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
Aggregations