use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiEntityTypeInterface method updateEntityType.
public StringApiResponse updateEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbEntityType.getTypeCode();
IApsEntity masterUserProfileType = this.getEntityManager().getEntityPrototype(typeCode);
if (null == masterUserProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
}
Map<String, AttributeInterface> attributes = this.getEntityManager().getEntityAttributePrototypes();
IApsEntity entityTypeToUpdate = jaxbEntityType.buildEntityType(this.getEntityManager().getEntityClass(), attributes);
this.checkEntityTypeToUpdate(jaxbEntityType, entityTypeToUpdate, response);
((IEntityTypesConfigurer) this.getEntityManager()).updateEntityPrototype(entityTypeToUpdate);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating entity type", t);
// ApsSystemUtils.logThrowable(t, this, "updateEntityType");
throw new ApsSystemException("Error updating entity type", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class JAXBEntityType method buildEntityType.
public IApsEntity buildEntityType(Class entityClass, Map<String, AttributeInterface> attributes) throws ApiException, Throwable {
List<ApiError> errors = new ArrayList<ApiError>();
IApsEntity entityType = null;
try {
entityType = (IApsEntity) entityClass.newInstance();
entityType.setTypeCode(this.getTypeCode());
entityType.setTypeDescr(this.getTypeDescription());
List<DefaultJAXBAttributeType> jabxAttributes = this.getAttributes();
for (int i = 0; i < jabxAttributes.size(); i++) {
try {
DefaultJAXBAttributeType jaxbAttributeType = jabxAttributes.get(i);
AttributeInterface attribute = jaxbAttributeType.createAttribute(attributes);
if (null != entityType.getAttribute(attribute.getName())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute '" + attribute.getName() + "' already defined");
}
entityType.addAttribute(attribute);
} catch (ApiException e) {
errors.addAll(e.getErrors());
}
}
} catch (Throwable t) {
_logger.error("error in buildEntityType", t);
// ApsSystemUtils.logThrowable(t, this, "buildEntityType");
throw t;
}
if (!errors.isEmpty())
throw new ApiException(errors);
return entityType;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method getLabel.
public JAXBI18nLabel getLabel(Properties properties) throws ApiException, ApsSystemException {
JAXBI18nLabel jaxbI18nLabel = null;
try {
String key = properties.getProperty("key");
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
if (null == labelGroups) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
}
jaxbI18nLabel = new JAXBI18nLabel(key, labelGroups);
} catch (ApiException ae) {
throw ae;
} catch (ApsSystemException t) {
_logger.error("error loading labels", t);
throw new ApsSystemException("Error loading labels", t);
}
return jaxbI18nLabel;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method updateInlineLabel.
public void updateInlineLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
try {
this.checkLabels(jaxbI18nLabel);
String key = jaxbI18nLabel.getKey();
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
_logger.info("KEY -> {} ", key);
boolean isEdit = (null != labelGroups);
if (!isEdit) {
labelGroups = new ApsProperties();
} else {
//
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
Iterator<Object> iterator = labels.keySet().iterator();
while (iterator.hasNext()) {
Object langKey = iterator.next();
labelGroups.put(langKey, labels.get(langKey));
}
if (isEdit) {
this.getI18nManager().updateLabelGroup(key, labelGroups);
_logger.info("*** EDIT DONE *** -> {}", labelGroups);
} else {
this.getI18nManager().addLabelGroup(key, labelGroups);
_logger.info("*** ADD DONE *** -> {}", labelGroups);
}
} catch (ApiException | ApsSystemException t) {
_logger.error("Error updating label {} ", t);
throw new ApiException("Error updating labels", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method checkLabels.
protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
try {
String key = jaxbI18nLabel.getKey();
if (null == key || key.trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
if (null == labels || labels.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
}
Iterator<Object> labelCodeIter = labels.keySet().iterator();
while (labelCodeIter.hasNext()) {
Object langCode = labelCodeIter.next();
Object value = labels.get(langCode);
if (null == value || value.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
}
}
} catch (ApiException ae) {
_logger.error("Error method checkLabels ", ae);
throw new ApiException("Error method checkLabels", ae);
}
}
Aggregations