use of org.meveo.model.customEntities.CustomEntityTemplate in project meveo by meveo-org.
the class CustomTableService method saveBatch.
/**
* Inserts a list of {@linkplain CustomEntityInstance} into the database in batch.
*
* @param cfts map of {@link CustomFieldTemplate}
* @param fields list of {@link CustomFieldTemplate}
* @param ceis list of transient {@link CustomEntityInstance}
* @param entityReferencesCache
* @throws BusinessException batch saving failed
*/
private void saveBatch(String sqlConnectionCode, Map<String, CustomFieldTemplate> cfts, List<CustomFieldTemplate> fields, List<CustomEntityInstance> ceis, Map<String, Map<String, String>> entityReferencesCache) throws BusinessException {
if (ceis == null || ceis.isEmpty()) {
return;
}
List<Map<String, Object>> values = ceis.stream().map(CustomEntityInstance::getCfValuesAsValues).collect(Collectors.toList());
values = convertValues(values, cfts, false);
values = replaceEntityReferences(sqlConnectionCode, fields, values, entityReferencesCache);
final CustomEntityTemplate cet = customEntityTemplateService.findByCodeOrDbTablename(ceis.get(0).getTableName());
customTableService.get().createInNewTx(sqlConnectionCode, cet, false, values);
}
use of org.meveo.model.customEntities.CustomEntityTemplate in project meveo by meveo-org.
the class CustomEntityTemplateService method update.
@Override
public CustomEntityTemplate update(CustomEntityTemplate cet) throws BusinessException {
CustomEntityTemplate oldValue = customFieldsCache.getCustomEntityTemplate(cet.getCode());
if (!EntityCustomizationUtils.validateOntologyCode(cet.getCode())) {
throw new IllegalArgumentException("The code of ontology elements must not contain numbers");
}
checkCrudEventListenerScript(cet);
ParamBean paramBean = paramBeanFactory.getInstance();
if (cet.getCustomEntityCategory() != null && !cet.getCustomEntityCategory().isTransient()) {
CustomEntityCategory cec = customEntityCategoryService.reattach(cet.getCustomEntityCategory());
cet.setCustomEntityCategory(cec);
}
CustomEntityTemplate cetUpdated = super.update(cet);
customFieldsCache.addUpdateCustomEntityTemplate(cet);
try {
permissionService.createIfAbsent(cet.getModifyPermission(), paramBean.getProperty("role.modifyAllCE", "ModifyAllCE"));
permissionService.createIfAbsent(cet.getReadPermission(), paramBean.getProperty("role.readAllCE", "ReadAllCE"));
} catch (Exception e) {
throw new RuntimeException(e);
}
flush();
// Synchronize custom fields storages with CET available storages
for (CustomFieldTemplate cft : customFieldTemplateService.findByAppliesToNoCache(cet.getAppliesTo()).values()) {
cft.setHasReferenceJpaEntity(cet.hasReferenceJpaEntity());
if (cft.getStoragesNullSafe() != null) {
for (DBStorageType storage : new ArrayList<>(cft.getStoragesNullSafe())) {
if (!cet.getAvailableStorages().contains(storage)) {
log.info("Remove storage '{}' from CFT '{}' of CET '{}'", storage, cft.getCode(), cet.getCode());
cft.getStoragesNullSafe().remove(storage);
customFieldTemplateService.update(cft);
}
}
}
}
// Synchronize neoj4 indexes
if (cet.getAvailableStorages() != null && cet.getAvailableStorages().contains(DBStorageType.NEO4J)) {
neo4jService.addUUIDIndexes(cet);
} else {
neo4jService.removeUUIDIndexes(cet);
}
var sqlConfs = sqlConfigurationService.listActiveAndInitialized();
// Handle SQL inheritance
if (cet.storedIn(DBStorageType.SQL)) {
if (oldValue.getSuperTemplate() != null && cet.getSuperTemplate() == null) {
// Inheritance removed
sqlConfs.forEach(sc -> customTableCreatorService.removeInheritance(sc.getCode(), cet));
} else if (oldValue.getSuperTemplate() == null && cet.getSuperTemplate() != null) {
// Inheritance added
sqlConfs.forEach(sc -> customTableCreatorService.addInheritance(sc.getCode(), cet));
}
}
return cetUpdated;
}
use of org.meveo.model.customEntities.CustomEntityTemplate in project meveo by meveo-org.
the class CustomEntityTemplateService method removeCETsByCategoryId.
/**
* retrieve Custom Entity Templates given by categoryId then remove it so that we can remove it in the cache
*
* @param categoryId if of the category
* @throws BusinessException the the CETs can't be removed
*/
public void removeCETsByCategoryId(Long categoryId) throws BusinessException {
TypedQuery<CustomEntityTemplate> query = getEntityManager().createNamedQuery("CustomEntityTemplate.getCETsByCategoryId", CustomEntityTemplate.class);
List<CustomEntityTemplate> results = query.setParameter("id", categoryId).getResultList();
if (CollectionUtils.isNotEmpty(results)) {
for (CustomEntityTemplate entityTemplate : results) {
remove(entityTemplate);
}
}
}
use of org.meveo.model.customEntities.CustomEntityTemplate in project meveo by meveo-org.
the class CustomRelationshipTemplateService method create.
@Override
public void create(CustomRelationshipTemplate crt) throws BusinessException {
if (!EntityCustomizationUtils.validateOntologyCode(crt.getCode())) {
throw new IllegalArgumentException("The code of ontology elements must not contain numbers");
}
if (crt.getStartNode() == null) {
throw new IllegalArgumentException("Can't create relation " + crt.getCode() + ": start node can't be null");
}
if (crt.getEndNode() == null) {
throw new IllegalArgumentException("Can't create relation " + crt.getCode() + ": end node can't be null");
}
super.create(crt);
try {
permissionService.createIfAbsent(crt.getModifyPermission(), paramBean.getProperty("role.modifyAllCR", "ModifyAllCR"));
permissionService.createIfAbsent(crt.getReadPermission(), paramBean.getProperty("role.readAllCR", "ReadAllCR"));
if (crt.getAvailableStorages().contains(DBStorageType.SQL)) {
customTableCreatorService.createCrtTable(crt);
}
customFieldsCache.addUpdateCustomRelationshipTemplate(crt);
} catch (Exception e) {
throw new RuntimeException(e);
}
// Synchronize start and end CETs
CustomEntityTemplate startCet = crt.getStartNode();
MeveoModule cetModule = cetService.findModuleOf(startCet);
cetService.addFilesToModule(startCet, cetModule);
CustomEntityTemplate endCrt = crt.getEndNode();
MeveoModule cet2Module = cetService.findModuleOf(endCrt);
cetService.addFilesToModule(endCrt, cet2Module);
}
use of org.meveo.model.customEntities.CustomEntityTemplate in project meveo by meveo-org.
the class CustomRelationshipTemplateService method remove.
@Override
public void remove(CustomRelationshipTemplate crt) throws BusinessException {
Map<String, CustomFieldTemplate> fields = customFieldTemplateService.findByAppliesToNoCache(crt.getAppliesTo());
for (CustomFieldTemplate cft : fields.values()) {
customFieldTemplateService.remove(cft.getId());
}
if (crt.getAvailableStorages().contains(DBStorageType.SQL)) {
customTableCreatorService.removeTable(repositoryService.findDefaultRepository().getCode(), SQLStorageConfiguration.getDbTablename(crt));
}
customFieldsCache.removeCustomRelationshipTemplate(crt);
permissionService.removeIfPresent(crt.getModifyPermission());
permissionService.removeIfPresent(crt.getReadPermission());
super.remove(crt);
CustomEntityTemplate startCet = crt.getStartNode();
MeveoModule cetModule = cetService.findModuleOf(startCet);
cetService.addFilesToModule(startCet, cetModule);
CustomEntityTemplate endCrt = crt.getEndNode();
MeveoModule cet2Module = cetService.findModuleOf(endCrt);
cetService.addFilesToModule(endCrt, cet2Module);
}
Aggregations