use of org.motechproject.mds.domain.MdsVersionedEntity in project motech by motech.
the class EntityServiceImpl method createEntity.
@Override
@Transactional
public EntityDto createEntity(EntityDto entityDto) {
String packageName = ClassName.getPackage(entityDto.getClassName());
boolean fromUI = StringUtils.isEmpty(packageName);
String username = getUsername();
if (fromUI) {
String className;
if (entityDto.getName().contains(" ")) {
entityDto.setName(entityDto.getName().trim());
StringBuilder stringBuilder = new StringBuilder();
String[] nameParts = entityDto.getName().split(" ");
for (String part : nameParts) {
if (part.length() > 0) {
stringBuilder.append(Character.toUpperCase(part.charAt(0)));
if (part.length() > 1) {
stringBuilder.append(part.substring(1));
}
}
}
className = String.format("%s.%s", Constants.PackagesGenerated.ENTITY, stringBuilder.toString());
} else {
// in this situation entity.getName() returns a simple name of class
className = String.format("%s.%s", Constants.PackagesGenerated.ENTITY, entityDto.getName());
}
entityDto.setClassName(className);
}
if (allEntities.contains(entityDto.getClassName())) {
throw new EntityAlreadyExistException(entityDto.getName());
}
Entity entity = allEntities.create(entityDto);
LOGGER.debug("Adding default fields to the entity, since it doesn't extend MdsEntity or MdsVersionedEntity");
if (!MdsEntity.class.getName().equalsIgnoreCase(entityDto.getSuperClass()) && !MdsVersionedEntity.class.getName().equalsIgnoreCase(entityDto.getSuperClass())) {
EntityHelper.addDefaultFields(entity, allTypes);
}
if (username != null) {
allEntityAudits.createAudit(entity, username);
}
return entity.toDto();
}
Aggregations