protected Object getValueExIgnoreUnfetched(Instance instance, String[] properties) { Object currentValue = null; Instance currentInstance = instance; for (String property : properties) { if (currentInstance == null) { break; } if (!PersistenceHelper.isLoaded(currentInstance, property)) { LoggerFactory.getLogger(WebAbstractTable.class) .warn("Ignored unfetched attribute {} of instance {} in Table cell", property, currentInstance); return null; } currentValue = currentInstance.getValue(property); if (currentValue == null) { break; } currentInstance = currentValue instanceof Instance ? (Instance) currentValue : null; } return currentValue; }
@Override public String toString() { MoreObjects.ToStringHelper builder = MoreObjects.toStringHelper("ScheduledTask") .omitNullValues() .addValue(id); String[] fields = new String[]{"beanName", "methodName", "className", "scriptName", "singleton", "period", "cron", "startDate"}; for (String field : fields) { if (PersistenceHelper.isLoaded(this, field)) { Object value = getValue(field); if (value instanceof Date) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); value = df.format(value); } builder.add(field, value); } } return builder.toString(); }
@MetaProperty public String getLocName() { if (PersistenceHelper.isLoaded(this, "procDefinition") && procDefinition != null && PersistenceHelper.isLoaded(procDefinition, "actId") && !Strings.isNullOrEmpty(procDefinition.getActId())) { ProcessMessagesService processMessagesService = AppBeans.get(ProcessMessagesService.class); String locName = processMessagesService.findMessage(procDefinition.getActId(), code); if (locName != null) return locName; } return name; } }
protected void addSpecificSuggestions(SourceCodeEditor sender, String text, int cursorPosition, List<Suggestion> suggestions) { if (cursorPosition <= 0) return; int colonIdx = text.substring(0, cursorPosition).lastIndexOf(":"); if (colonIdx < 0) return; List<String> strings = new ArrayList<>(); strings.add(SESSION_PREFIX + "userGroupId"); strings.add(SESSION_PREFIX + "userId"); strings.add(SESSION_PREFIX + "userLogin"); if (PersistenceHelper.isLoaded(getItem(), "group") && getItem().getGroup() != null) { List<String> attributeNames = userManagementService.getSessionAttributeNames(getItem().getGroup().getId()); for (String name : attributeNames) { strings.add(SESSION_PREFIX + name); } } Collections.sort(strings); String entered = text.substring(colonIdx + 1, cursorPosition); for (String string : strings) { if (string.startsWith(entered)) { suggestions.add(new Suggestion(sender.getAutoCompleteSupport(), string, string.substring(entered.length()), "", cursorPosition, cursorPosition)); } } }
protected void storeIndexFields(Report report) { if (PersistenceHelper.isLoaded(report, "xml")) { StringBuilder entityTypes = new StringBuilder(IDX_SEPARATOR); if (report.getInputParameters() != null) { for (ReportInputParameter parameter : report.getInputParameters()) { if (isNotBlank(parameter.getEntityMetaClass())) { entityTypes.append(parameter.getEntityMetaClass()) .append(IDX_SEPARATOR); } } } report.setInputEntityTypesIdx(entityTypes.length() > 1 ? entityTypes.toString() : null); StringBuilder screens = new StringBuilder(IDX_SEPARATOR); if (report.getReportScreens() != null) { for (ReportScreen reportScreen : report.getReportScreens()) { screens.append(reportScreen.getScreenId()) .append(IDX_SEPARATOR); } } report.setScreensIdx(screens.length() > 1 ? screens.toString() : null); StringBuilder roles = new StringBuilder(IDX_SEPARATOR); if (report.getRoles() != null) { for (Role role : report.getRoles()) { roles.append(role.getId().toString()) .append(IDX_SEPARATOR); } } report.setRolesIdx(roles.length() > 1 ? roles.toString() : null); } }
protected boolean propertyWritingAllowed(MetaProperty metaProperty, Entity entity) { return !"id".equals(metaProperty.getName()) && (DynamicAttributesUtils.isDynamicAttribute(metaProperty) || (entity instanceof AbstractNotPersistentEntity) || !metadataTools.isPersistent(metaProperty) || (metadataTools.isPersistent(metaProperty) && PersistenceHelper.isLoaded(entity, metaProperty.getName()))); }
if (!property.getRange().isClass() || !property.getRange().asClass().equals(contextEntityMetaClass) || !PersistenceHelper.isLoaded(entity, property.getName())) continue;
&& PersistenceHelper.isLoaded(createdItem, inverseProp.getName()) && Objects.equals(createdItem.getValue(inverseProp.getName()), masterDs.getItem())) { parentCollectionDs.removeItem(createdItem);
protected Collection<Entity> getCollection(MetaProperty property) { MetaProperty inverseProperty = property.getInverse(); if (inverseProperty == null) { log.warn("Inverse property not found for property {}", property); Collection<Entity> value = entity.getValue(property.getName()); return value == null ? Collections.EMPTY_LIST : value; } String invPropName = inverseProperty.getName(); String qlStr = "select e from " + property.getRange().asClass().getName() + " e where e." + invPropName + "." + primaryKeyName + " = ?1"; Query query = entityManager.createQuery(qlStr); query.setParameter(1, entity.getId()); List<Entity> list = query.getResultList(); // If the property is not loaded, it means it was not modified and further check is not needed if (!PersistenceHelper.isLoaded(entity, property.getName())) { return list; } // Check whether the collection items still belong to the master entity, because they could be changed in the // current transaction that did not affect the database yet List<Entity> result = new ArrayList<>(list.size()); for (Entity item : list) { Entity master = item.getValue(invPropName); if (entity.equals(master)) result.add(item); } return result; }
/** * This method is required for multi-level composition, when a user deletes records from nested editors, saves them * and then reopens. When an editor is opened, we reload the item from the database, hence we need to remove * nested items previously deleted by the user. */ protected void handlePreviouslyDeletedCompositionItems(Entity entity, DatasourceImplementation parentDs) { Metadata metadata = getBeanLocator().get(Metadata.NAME); for (MetaProperty property : metadata.getClassNN(entity.getClass()).getProperties()) { if (!PersistenceHelper.isLoaded(entity, property.getName())) return; if (property.getType() == MetaProperty.Type.COMPOSITION) { for (Datasource datasource : parentDs.getDsContext().getAll()) { if (datasource instanceof NestedDatasource && ((NestedDatasource) datasource).getMaster().equals(parentDs)) { Object value = entity.getValue(property.getName()); if (value instanceof Collection) { Collection collection = (Collection) value; //noinspection unchecked collection.removeAll(((DatasourceImplementation) datasource).getItemsToDelete()); } } } } } }
if (PersistenceHelper.isLoaded(entity, relatedPropertyName)) { Entity refEntity = entity.getValue(property.getName()); if (refEntity == null) {
Multimap<String, Object> filteredData = BaseEntityInternalAccess.getFilteredData(baseGenericIdEntity); for (MetaProperty property : metaClass.getProperties()) { if (metadataTools.isPersistent(property) && PersistenceHelper.isLoaded(entity, property.getName())) { Object value = entity.getValue(property.getName()); if (value instanceof Collection) {
protected void setReferenceNull(Entity entity, MetaProperty property) { Range range = property.getRange(); if (metadata.getTools().isOwningSide(property) && !range.getCardinality().isMany()) { if (PersistenceHelper.isLoaded(entity, property.getName())) { entity.setValue(property.getName(), null); } else { hardSetReferenceNull(entity, property); } } }
@SuppressWarnings("unchecked") protected void writeFields(JsonWriter out, Entity entity) throws IOException { for (MetaProperty property : entity.getMetaClass().getProperties()) { if (!"id".equalsIgnoreCase(property.getName()) && !property.isReadOnly() && !exclude(entity.getClass(), property.getName()) && PersistenceHelper.isLoaded(entity, property.getName())) { Range propertyRange = property.getRange(); if (propertyRange.isDatatype()) { writeSimpleProperty(out, entity, property); } else if (propertyRange.isClass()) { Object value = entity.getValue(property.getName()); if (value instanceof Entity) { out.name(property.getName()); writeEntity(out, (Entity) value); } else if (value instanceof Collection) { out.name(property.getName()); writeCollection(out, (Collection) value); } } else if (propertyRange.isEnum()) { out.name(property.getName()); out.value(propertyRange.asEnumeration().format(entity.getValue(property.getName()))); } } } }
&& !PersistenceHelper.isLoaded(entity, metaProperty.getName())) { continue;
protected Entity getReference(Entity entity, MetaProperty property) { if (PersistenceHelper.isLoaded(entity, property.getName())) return entity.getValue(property.getName()); else { Query query = entityManager.createQuery( "select e." + property.getName() + " from " + entity.getMetaClass().getName() + " e where e." + primaryKeyName + " = ?1"); query.setParameter(1, entity.getId()); Object refEntity = query.getFirstResult(); return (Entity) refEntity; } }
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity; for (MetaProperty property : metaClass.getProperties()) { if (metadataTools.isPersistent(property) && PersistenceHelper.isLoaded(entity, property.getName())) { Object value = entity.getValue(property.getName()); if (value instanceof Collection) {
String name = srcProperty.getName(); if (!PersistenceHelper.isLoaded(source, name)) { continue;
protected void replaceMasterCopies(Entity entity, NestedDatasource datasource) { Datasource masterDs = datasource.getMaster(); MetaProperty metaProperty = datasource.getProperty(); if (masterDs != null && metaProperty != null) { MetaProperty inverseProp = metaProperty.getInverse(); if (inverseProp != null && !inverseProp.getRange().getCardinality().isMany()) { MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(inverseProp.getDomain()); if (metaClass.equals(datasource.getMetaClass()) && (PersistenceHelper.isLoaded(entity, inverseProp.getName()) && entity.getValue(inverseProp.getName()) != null)) // replace master only if it's already set { Object masterItem = null; if (masterDs instanceof CollectionDatasource) { Entity value = entity.getValue(inverseProp.getName()); if (value != null) { Object id = value.getId(); //noinspection unchecked masterItem = ((CollectionDatasource) masterDs).getItem(id); } } else { masterItem = masterDs.getItem(); } if (masterItem != null) { // CAUTION need to rework this mechanism in case of two or more nested collection datasources ((AbstractInstance) entity).setValue(inverseProp.getName(), masterItem, false); } } } } }
if (value != null && checkIfEntityBelongsToMaster(property, value)) { if (!(value instanceof SoftDelete)) { if (PersistenceHelper.isLoaded(entity, property.getName())) { entity.setValue(property.getName(), null); entityManager.remove(value);