public MetaClass getMetaClass() { return loadInfo.getMetaClass(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InstanceRef that = (InstanceRef) o; if (!loadInfo.getId().equals(that.loadInfo.getId())) return false; if (!loadInfo.getMetaClass().equals(that.loadInfo.getMetaClass())) return false; return true; }
@Override public int hashCode() { int result1 = loadInfo.getId().hashCode(); result1 = 31 * result1 + loadInfo.getMetaClass().hashCode(); return result1; } }
/** * Check whether an info about the given entity instance is contained in the collection. * * @param collection collection of EntityLoadInfo objects * @param entity entity instance * @return true if the collection contains an info about the given entity instance. View part of the info is ignored. */ public boolean contains(Collection<EntityLoadInfo> collection, Entity entity) { Preconditions.checkNotNullArgument(collection, "collection is null"); Preconditions.checkNotNullArgument(entity, "entity is null"); MetaClass metaClass = metadata.getClassNN(entity.getClass()); for (EntityLoadInfo info : collection) { if (metaClass.equals(info.getMetaClass()) && entity.getId().equals(info.getId())) return true; } return false; } }
protected Entity loadEntityInstance(EntityLoadInfo info) { if (info.isNewEntity()) { return metadata.create(info.getMetaClass()); } //noinspection unchecked LoadContext<Entity> ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) { View view = viewRepository.findView(info.getMetaClass(), info.getViewName()); if (view != null) { ctx.setView(view); } else { log.warn("Unable to find view \"{}\" for entity \"{}\"", info.getViewName(), info.getMetaClass()); } } Entity entity; try { entity = dataService.load(ctx); } catch (Exception e) { log.warn("Unable to load item: {}", info, e); return null; } return entity; }
private Entity loadEntity(EntityLoadInfo entityLoadInfo) { DataManager dataManager = getDataManager(); return dataManager.load(getLoadContextForForEntityLoadInfo(entityLoadInfo.getMetaClass(), entityLoadInfo.getId())); }
public InstanceRef parseInstanceRefAndRegister(String fullId) throws InstantiationException, IllegalAccessException { EntityLoadInfo loadInfo; if (!fullId.startsWith("NEW-")) { loadInfo = EntityLoadInfo.parse(fullId); if (loadInfo == null) { throw new RuntimeException("Cannot parse id: " + fullId); } InstanceRef existingRef = instanceRefs.get(loadInfo.getMetaClass().getName() + "-" + loadInfo.getId().toString()); if (existingRef != null) { return existingRef; } } else { int idDashIndex = StringUtils.ordinalIndexOf(fullId, "-", 2); if (idDashIndex == -1) { String entityName = fullId.substring("NEW-".length()); String generatedId = generateId(entityName); fullId = fullId + "-" + generatedId; } loadInfo = EntityLoadInfo.parse(fullId); if (loadInfo == null) { throw new RuntimeException("Cannot parse id: " + fullId); } } if (loadInfo.isNewEntity()) newInstanceIds.add(loadInfo.toString()); InstanceRef result = new InstanceRef(loadInfo); instanceRefs.put(loadInfo.getMetaClass().getName() + "-" + loadInfo.getId().toString(), result); return result; }
private Entity loadEntity(EntityLoadInfo entityLoadInfo) { DataManager dataManager = getDataManager(); return dataManager.load(getLoadContextForForEntityLoadInfo(entityLoadInfo.getMetaClass(), entityLoadInfo.getId())); }
@Override public Object build(String string) { if (StringUtils.isBlank(string)) return null; EntityLoadInfo info = EntityLoadInfo.parse(string); if (info == null) throw new IllegalArgumentException("Invalid entity info: " + string); LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) ctx.setView(info.getViewName()); return ds.load(ctx); } }
/** * Creates new entity instance from {@link com.haulmont.cuba.core.global.EntityLoadInfo} * and reset fields values */ protected Entity createEmptyInstance(EntityLoadInfo loadInfo) throws IllegalAccessException, InstantiationException { MetaClass metaClass = loadInfo.getMetaClass(); Entity instance = metadata.create(metaClass); for (MetaProperty metaProperty : metaClass.getProperties()) { if (!metaProperty.isReadOnly()) instance.setValue(metaProperty.getName(), null); } return instance; }
/** * Creates new entity instance from {@link com.haulmont.cuba.core.global.EntityLoadInfo} * and reset fields values */ protected Entity createEmptyInstance(EntityLoadInfo loadInfo) throws IllegalAccessException, InstantiationException { MetaClass metaClass = loadInfo.getMetaClass(); Entity instance = metadata.create(metaClass); for (MetaProperty metaProperty : metaClass.getProperties()) { if (!metaProperty.isReadOnly()) instance.setValue(metaProperty.getName(), null); } return instance; }
setField(instance, "id", loadInfo.getId()); MetaClass metaClass = loadInfo.getMetaClass(); Iterator iter = json.keys(); while (iter.hasNext()) {
protected Entity loadEntityInstance(EntityLoadInfo info) { LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) { ctx.setView(info.getViewName()); } //noinspection unchecked return dataService.load(ctx); }
protected Entity loadEntityInstance(EntityLoadInfo info) { Metadata metadata = AppBeans.get(Metadata.class); if (info.isNewEntity()) { return metadata.create(info.getMetaClass()); } LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) ctx.setView(info.getViewName()); Entity entity; try { DataManager dataManager = AppBeans.get(DataManager.class); entity = dataManager.load(ctx); } catch (Exception e) { throw new BpmException("Unable to load item: " + info, e); } return entity; } }
View view = null; if (info.getViewName() != null) { view = metadata.getViewRepository().getView(info.getMetaClass(), info.getViewName()); Class javaClass = info.getMetaClass().getJavaClass(); if (view != null) { entity = em.find(javaClass, info.getId(), view);
@Override public Object convertFromString(Class parameterClass, String paramValueStr) { if (paramValueStr == null) { return null; } else if (String.class.isAssignableFrom(parameterClass)) { return paramValueStr; } else if (Entity.class.isAssignableFrom(parameterClass)) { EntityLoadInfo entityLoadInfo = EntityLoadInfo.parse(paramValueStr); if (entityLoadInfo != null) { return dataManager.load(new LoadContext(entityLoadInfo.getMetaClass()).setId(entityLoadInfo.getId()).setView(View.BASE)); } else { UUID id = UUID.fromString(paramValueStr); return dataManager.load(new LoadContext(parameterClass).setId(id).setView(View.BASE)); } } else { Datatype datatype = Datatypes.get(parameterClass); if (datatype != null) { try { return datatype.parse(paramValueStr); } catch (ParseException e) { throw new ReportingException( String.format("Couldn't read value [%s] with datatype [%s].", paramValueStr, datatype)); } } else { return convertFromStringUnresolved(parameterClass, paramValueStr); } } } }
entityLoadInfo = EntityLoadInfo.parse(idPrimitive.getAsString()); if (entityLoadInfo != null) { resultMetaClass = entityLoadInfo.getMetaClass();
return; MetaClass metaClass = loadInfo.getMetaClass(); if (!readPermitted(metaClass)) { response.sendError(HttpServletResponse.SC_FORBIDDEN);
public InstanceRef(EntityLoadInfo loadInfo) throws InstantiationException, IllegalAccessException { if (loadInfo == null) throw new NullPointerException("No load info passed"); this.loadInfo = loadInfo; MetaClass childMetaClass = loadInfo.getMetaClass(); if (!Strings.isNullOrEmpty(loadInfo.getViewName()) && !loadInfo.isNewEntity()) { DataService dataService = AppBeans.get(DataService.class); LoadContext<BaseGenericIdEntity<Object>> ctx = new LoadContext<>(loadInfo.getMetaClass()); ctx.setId(loadInfo.getId()).setView(loadInfo.getViewName()); instance = dataService.load(ctx); if (instance == null) { throw new RuntimeException("Entity with loadInfo " + loadInfo + " not found"); } } else { //noinspection unchecked instance = (BaseGenericIdEntity<Object>) AppBeans.get(Metadata.class).create(childMetaClass); if (!loadInfo.isNewEntity()) { for (MetaProperty metaProperty : childMetaClass.getProperties()) { if (!metaProperty.getRange().isClass()) { try { instance.setValue(metaProperty.getName(), null); } catch (Exception ignored) { } } } } } instance.setId(this.loadInfo.getId()); }
Entity ref = metadata.create(loadInfo.getMetaClass()); ref.setValue("id", loadInfo.getId()); setField(bean, fieldName, ref);