use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class LoadSubstitutionsTest method testQuerySubstitutions.
@Test
public void testQuerySubstitutions() throws Exception {
ViewRepository viewRepository = AppBeans.get(ViewRepository.NAME);
View userView = new View(new View.ViewParams().src(viewRepository.getView(User.class, View.LOCAL)));
View substitutedUserView = new View(User.class);
substitutedUserView.addProperty("login");
View substitutionsView = new View(UserSubstitution.class);
substitutionsView.addProperty("substitutedUser", substitutedUserView);
substitutionsView.addProperty("startDate");
userView.addProperty("substitutions", substitutionsView);
User loadedUser;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
loadedUser = em.find(User.class, user.getId(), userView);
tx.commit();
}
assertNotNull(loadedUser);
assertNotNull(loadedUser.getSubstitutions());
Assert.assertEquals(1, loadedUser.getSubstitutions().size());
UserSubstitution loadedSubstitution = loadedUser.getSubstitutions().iterator().next();
assertEquals(user, loadedSubstitution.getUser());
assertEquals(substitutedUser, loadedSubstitution.getSubstitutedUser());
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class SystemInfoWindow method generateInsert.
public void generateInsert() {
scriptArea.setEditable(true);
if (item instanceof Role) {
View localView = metadata.getViewRepository().getView(Role.class, View.LOCAL);
View roleView = new View(localView, Role.class, "role-export-view", true).addProperty("permissions", metadata.getViewRepository().getView(Permission.class, View.LOCAL));
item = getDsContext().getDataSupplier().reload(item, roleView);
StringBuilder result = new StringBuilder();
result.append(sqlGenerationService.generateInsertScript(item)).append("\n");
for (Permission permission : ((Role) item).getPermissions()) {
result.append(sqlGenerationService.generateInsertScript(permission)).append("\n");
}
scriptArea.setValue(result.toString());
} else {
scriptArea.setValue(sqlGenerationService.generateInsertScript(item));
}
showScriptArea();
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class PropertyDatasourceImpl method getView.
@Override
public View getView() {
if (view == null) {
MetaClass metaMetaClass = masterDs.getMetaClass();
if (metadata.getTools().isPersistent(metaMetaClass) || metadata.getTools().isEmbeddable(metaMetaClass)) {
View masterView = masterDs.getView();
if (masterView == null) {
throw new DevelopmentException("No view for datasource " + masterDs.getId(), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId()));
}
ViewProperty property = masterView.getProperty(metaProperty.getName());
if (property == null) {
return null;
}
if (property.getView() == null) {
throw new DevelopmentException(String.format("Invalid view definition: %s. Property '%s' must have a view", masterView, property), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId(), "masterView", masterView, "property", property));
}
view = metadata.getViewRepository().findView(getMetaClass(), property.getView().getName());
// anonymous (nameless) view
if (view == null)
view = property.getView();
}
}
return view;
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class RuntimePropsDatasourceImpl method initMetaClass.
protected void initMetaClass(Entity entity) {
if (!(entity instanceof BaseGenericIdEntity)) {
throw new IllegalStateException("This datasource can contain only entity with subclass of BaseGenericIdEntity");
}
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity;
if (PersistenceHelper.isNew(baseGenericIdEntity) && baseGenericIdEntity.getDynamicAttributes() == null) {
baseGenericIdEntity.setDynamicAttributes(new HashMap<>());
}
@SuppressWarnings("unchecked") Map<String, CategoryAttributeValue> dynamicAttributes = baseGenericIdEntity.getDynamicAttributes();
Preconditions.checkNotNullArgument(dynamicAttributes, "Dynamic attributes should be loaded explicitly");
if (baseGenericIdEntity instanceof Categorized) {
category = ((Categorized) baseGenericIdEntity).getCategory();
}
if (!initializedBefore && category == null) {
category = getDefaultCategory();
if (baseGenericIdEntity.getMetaClass().getProperty("category") != null) {
baseGenericIdEntity.setValue("category", category);
}
}
item = new DynamicAttributesEntity(baseGenericIdEntity, attributes);
if (PersistenceHelper.isNew(entity) || categoryChanged) {
dynamicAttributesGuiTools.initDefaultAttributeValues(baseGenericIdEntity, resolveCategorizedEntityClass());
}
view = new View(DynamicAttributesEntity.class, false);
Collection<MetaProperty> properties = metaClass.getProperties();
for (MetaProperty property : properties) {
view.addProperty(property.getName());
}
valid();
initializedBefore = true;
fireItemChanged(null);
}
use of com.haulmont.cuba.core.global.View in project cuba by cuba-platform.
the class ViewRepositoryInfo method dump.
protected void dump(ViewProperty viewProperty, StringBuilder content, String indent) {
content.append("\n");
content.append(indent);
content.append("- ").append(viewProperty.getName());
View innerView = viewProperty.getView();
if (innerView != null) {
if (StringUtils.isNotEmpty(innerView.getName())) {
content.append(" -> ").append(metadata.getSession().getClass(innerView.getEntityClass()).getName()).append("/").append(innerView.getName());
} else {
for (ViewProperty innerProperty : innerView.getProperties()) {
dump(innerProperty, content, " " + indent);
}
}
}
}
Aggregations