@Test(expected = EntityAlreadyExistException.class) public void shouldNotCreateTwiceSameEntity() throws Exception { when(entityDto.getClassName()).thenReturn(CLASS_NAME); when(allEntities.contains(CLASS_NAME)).thenReturn(true); entityService.createEntity(entityDto); }
@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 { 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(); }
EntityServiceImpl implements EntityService { @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 { 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(); } }
EntityServiceImpl implements EntityService { @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 { 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(); }  }
EntityServiceImpl implements EntityService { @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 { 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(); }  @Override @Transactional Long getCurrentSchemaVersion(String className); @Override @Transactional void incrementVersion(Long entityId); @Override @Transactional EntityDto createEntity(EntityDto entityDto); @Override @Transactional DraftResult saveDraftEntityChanges(Long entityId, DraftData draftData, String username); @Override @Transactional DraftResult saveDraftEntityChanges(Long entityId, DraftData draftData); @Override @Transactional void abandonChanges(Long entityId); @Override @Transactional List<String> commitChanges(Long entityId, String changesOwner); @Override @Transactional List<String> commitChanges(Long entityId); @Override @Transactional List<EntityDto> listWorkInProgress(); @Override @Transactional AdvancedSettingsDto getAdvancedSettings(Long entityId); @Override @Transactional AdvancedSettingsDto getAdvancedSettings(Long entityId, boolean committed); @Override @Transactional AdvancedSettingsDto safeGetAdvancedSettingsCommitted(String entityClassName); @Override @Transactional void updateRestOptions(Long entityId, RestOptionsDto restOptionsDto); @Override @Transactional void updateTracking(Long entityId, TrackingDto trackingDto); @Override @Transactional void addLookups(EntityDto entityDto, LookupDto... lookups); @Override @Transactional void addLookups(EntityDto entityDto, Collection<LookupDto> lookups); @Override @Transactional void addLookups(Long entityId, LookupDto... lookups); @Override @Transactional void addLookups(Long entityId, Collection<LookupDto> lookups); @Override @Transactional Map<String, FieldDto> getLookupFieldsMapping(Long entityId, String lookupName); @Override @Transactional void deleteEntity(Long entityId); @Override @Transactional List<EntityDto> listEntities(); @Override @Transactional List<EntityDto> listEntities(boolean withSecurityCheck); @Override @Transactional List<EntityDto> listEntitiesByBundle(String bundleSymbolicName); @Override @Transactional EntityDto getEntity(Long entityId); @Override @Transactional EntityDto getEntityByClassName(String className); @Override @Transactional List<EntityDto> findEntitiesByPackage(String packageName); @Override @Transactional List<LookupDto> getEntityLookups(Long entityId); @Override @Transactional List<FieldDto> getFields(Long entityId); @Override @Transactional List<FieldDto> getEntityFields(Long entityId); @Override @Transactional List<FieldDto> getEntityFieldsForUI(Long entityId); @Override @Transactional SchemaHolder getSchema(); @Override @Transactional List<FieldDto> getEntityFieldsByClassName(String className); @Override @Transactional List<FieldDto> getEntityFieldsByClassNameForUI(String className); @Override @Transactional FieldDto findFieldByName(Long entityId, String name); @Override @Transactional FieldDto findEntityFieldByName(Long entityId, String name); @Override @Transactional FieldDto getEntityFieldById(Long entityId, Long fieldId); @Override @Transactional EntityDto getEntityForEdit(Long entityId); @Override @Transactional EntityDraft getEntityDraft(Long entityId); @Override @Transactional EntityDraft getEntityDraft(Long entityId, String username); @Override @Transactional void addFields(EntityDto entity, Collection<FieldDto> fields); @Override @Transactional void addFields(Long entityId, FieldDto... fields); @Override @Transactional void addFields(EntityDto entity, FieldDto... fields); @Override @Transactional void addFields(Long entityId, Collection<FieldDto> fields); @Override @Transactional void addFilterableFields(EntityDto entityDto, Collection<String> fieldNames); @Override @Transactional EntityDto updateDraft(Long entityId); @Override @Transactional LookupDto getLookupByName(Long entityId, String lookupName); @Override @Transactional List<FieldDto> getDisplayFields(Long entityId); @Override @Transactional void addNonEditableFields(EntityDto entityDto, Map<String, Boolean> nonEditableFields); @Override @Transactional void addDisplayedFields(EntityDto entityDto, Map<String, Long> positions); @Override @Transactional void updateSecurityOptions(Long entityId, SecurityMode securityMode, Set<String> securityMembers, SecurityMode readOnlySecurityMode, Set<String> readOnlySecurityMembers); @Override @Transactional void updateMaxFetchDepth(Long entityId, Integer maxFetchDepth); @Autowired void setAllEntities(AllEntities allEntities); @Autowired void setAllTypes(AllTypes allTypes); @Autowired void setAllEntityDrafts(AllEntityDrafts allEntityDrafts); @Autowired void setAllEntityAudits(AllEntityAudits allEntityAudits); @Autowired void setAllUserPreferences(AllUserPreferences allUserPreferences); @Autowired void setMDSConstructor(MDSConstructor mdsConstructor); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setEntityValidator(EntityValidator entityValidator); @Autowired void setComboboxDataMigrationHelper(ComboboxDataMigrationHelper comboboxDataMigrationHelper); @Autowired void setUserPreferencesService(UserPreferencesService userPreferencesService); }
EntityServiceImpl implements EntityService { @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 { 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(); }  @Override @Transactional Long getCurrentSchemaVersion(String className); @Override @Transactional void incrementVersion(Long entityId); @Override @Transactional EntityDto createEntity(EntityDto entityDto); @Override @Transactional DraftResult saveDraftEntityChanges(Long entityId, DraftData draftData, String username); @Override @Transactional DraftResult saveDraftEntityChanges(Long entityId, DraftData draftData); @Override @Transactional void abandonChanges(Long entityId); @Override @Transactional List<String> commitChanges(Long entityId, String changesOwner); @Override @Transactional List<String> commitChanges(Long entityId); @Override @Transactional List<EntityDto> listWorkInProgress(); @Override @Transactional AdvancedSettingsDto getAdvancedSettings(Long entityId); @Override @Transactional AdvancedSettingsDto getAdvancedSettings(Long entityId, boolean committed); @Override @Transactional AdvancedSettingsDto safeGetAdvancedSettingsCommitted(String entityClassName); @Override @Transactional void updateRestOptions(Long entityId, RestOptionsDto restOptionsDto); @Override @Transactional void updateTracking(Long entityId, TrackingDto trackingDto); @Override @Transactional void addLookups(EntityDto entityDto, LookupDto... lookups); @Override @Transactional void addLookups(EntityDto entityDto, Collection<LookupDto> lookups); @Override @Transactional void addLookups(Long entityId, LookupDto... lookups); @Override @Transactional void addLookups(Long entityId, Collection<LookupDto> lookups); @Override @Transactional Map<String, FieldDto> getLookupFieldsMapping(Long entityId, String lookupName); @Override @Transactional void deleteEntity(Long entityId); @Override @Transactional List<EntityDto> listEntities(); @Override @Transactional List<EntityDto> listEntities(boolean withSecurityCheck); @Override @Transactional List<EntityDto> listEntitiesByBundle(String bundleSymbolicName); @Override @Transactional EntityDto getEntity(Long entityId); @Override @Transactional EntityDto getEntityByClassName(String className); @Override @Transactional List<EntityDto> findEntitiesByPackage(String packageName); @Override @Transactional List<LookupDto> getEntityLookups(Long entityId); @Override @Transactional List<FieldDto> getFields(Long entityId); @Override @Transactional List<FieldDto> getEntityFields(Long entityId); @Override @Transactional List<FieldDto> getEntityFieldsForUI(Long entityId); @Override @Transactional SchemaHolder getSchema(); @Override @Transactional List<FieldDto> getEntityFieldsByClassName(String className); @Override @Transactional List<FieldDto> getEntityFieldsByClassNameForUI(String className); @Override @Transactional FieldDto findFieldByName(Long entityId, String name); @Override @Transactional FieldDto findEntityFieldByName(Long entityId, String name); @Override @Transactional FieldDto getEntityFieldById(Long entityId, Long fieldId); @Override @Transactional EntityDto getEntityForEdit(Long entityId); @Override @Transactional EntityDraft getEntityDraft(Long entityId); @Override @Transactional EntityDraft getEntityDraft(Long entityId, String username); @Override @Transactional void addFields(EntityDto entity, Collection<FieldDto> fields); @Override @Transactional void addFields(Long entityId, FieldDto... fields); @Override @Transactional void addFields(EntityDto entity, FieldDto... fields); @Override @Transactional void addFields(Long entityId, Collection<FieldDto> fields); @Override @Transactional void addFilterableFields(EntityDto entityDto, Collection<String> fieldNames); @Override @Transactional EntityDto updateDraft(Long entityId); @Override @Transactional LookupDto getLookupByName(Long entityId, String lookupName); @Override @Transactional List<FieldDto> getDisplayFields(Long entityId); @Override @Transactional void addNonEditableFields(EntityDto entityDto, Map<String, Boolean> nonEditableFields); @Override @Transactional void addDisplayedFields(EntityDto entityDto, Map<String, Long> positions); @Override @Transactional void updateSecurityOptions(Long entityId, SecurityMode securityMode, Set<String> securityMembers, SecurityMode readOnlySecurityMode, Set<String> readOnlySecurityMembers); @Override @Transactional void updateMaxFetchDepth(Long entityId, Integer maxFetchDepth); @Autowired void setAllEntities(AllEntities allEntities); @Autowired void setAllTypes(AllTypes allTypes); @Autowired void setAllEntityDrafts(AllEntityDrafts allEntityDrafts); @Autowired void setAllEntityAudits(AllEntityAudits allEntityAudits); @Autowired void setAllUserPreferences(AllUserPreferences allUserPreferences); @Autowired void setMDSConstructor(MDSConstructor mdsConstructor); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setEntityValidator(EntityValidator entityValidator); @Autowired void setComboboxDataMigrationHelper(ComboboxDataMigrationHelper comboboxDataMigrationHelper); @Autowired void setUserPreferencesService(UserPreferencesService userPreferencesService);  }