use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiEntityTypeInterface method addEntityType.
public StringApiResponse addEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
IEntityManager manager = this.getEntityManager();
String typeCode = jaxbEntityType.getTypeCode();
IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
if (null != masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' already exists");
}
if (typeCode == null || typeCode.length() != 3) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
}
Map<String, AttributeInterface> attributes = manager.getEntityAttributePrototypes();
IApsEntity newEntityType = jaxbEntityType.buildEntityType(manager.getEntityClass(), attributes);
this.checkNewEntityType(jaxbEntityType, newEntityType, response);
((IEntityTypesConfigurer) manager).addEntityPrototype(newEntityType);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error extracting entity type", t);
// ApsSystemUtils.logThrowable(t, this, "getEntityType");
throw new ApsSystemException("Error extracting entity type", t);
}
return response;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiEntityTypeInterface method getEntityType.
public JAXBEntityType getEntityType(Properties properties) throws Throwable {
JAXBEntityType jaxbEntityType = null;
try {
IEntityManager manager = this.getEntityManager();
String typeCode = properties.getProperty(this.getTypeCodeParamName());
IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
if (null == masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' does not exist");
}
jaxbEntityType = this.createJAXBEntityType(masterEntityType);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting entity type", t);
// ApsSystemUtils.logThrowable(t, this, "getEntityType");
throw new ApsSystemException("Error extracting entity type", t);
}
return jaxbEntityType;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiEntityTypeInterface method getEntityTypes.
public StringListApiResponse getEntityTypes(Properties properties) throws Throwable {
StringListApiResponse response = new StringListApiResponse();
try {
IEntityManager manager = this.getEntityManager();
Map<String, IApsEntity> prototypes = manager.getEntityPrototypes();
List<String> codes = new ArrayList<String>();
codes.addAll(prototypes.keySet());
Collections.sort(codes);
response.setResult(codes, null);
} catch (Throwable t) {
_logger.error("Error extracting entity type codes", t);
// ApsSystemUtils.logThrowable(t, this, "getEntityTypes");
throw new ApsSystemException("Error extracting entity type codes", t);
}
return response;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity 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;
}
Aggregations