mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
Refs #1402 Ability to define middleware views which are not deployed to client
This commit is contained in:
parent
7ddab51f0c
commit
cfa62af17a
@ -109,4 +109,13 @@ public interface ClientConfig extends Config {
|
|||||||
@DefaultString("CTRL-DELETE")
|
@DefaultString("CTRL-DELETE")
|
||||||
@Property("cuba.gui.tableRemoveShortcut")
|
@Property("cuba.gui.tableRemoveShortcut")
|
||||||
String getTableRemoveShortcut();
|
String getTableRemoveShortcut();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If false, the client loads all server views on startup.
|
||||||
|
* If true, it loads views one by one only when needed.
|
||||||
|
* <p>Lazy loading is required if the server can contain views for entities, not available on the client.</p>
|
||||||
|
*/
|
||||||
|
@Property("cuba.lazyLoadServerViews")
|
||||||
|
@DefaultBoolean(false)
|
||||||
|
boolean getLazyLoadServerViews();
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,9 @@ import com.haulmont.bali.util.ReflectionHelper;
|
|||||||
import com.haulmont.chile.core.loader.ChileMetadataLoader;
|
import com.haulmont.chile.core.loader.ChileMetadataLoader;
|
||||||
import com.haulmont.chile.core.loader.MetadataLoader;
|
import com.haulmont.chile.core.loader.MetadataLoader;
|
||||||
import com.haulmont.chile.core.model.MetaClass;
|
import com.haulmont.chile.core.model.MetaClass;
|
||||||
|
import com.haulmont.cuba.client.ClientConfig;
|
||||||
import com.haulmont.cuba.core.app.ServerInfoService;
|
import com.haulmont.cuba.core.app.ServerInfoService;
|
||||||
import com.haulmont.cuba.core.global.Metadata;
|
import com.haulmont.cuba.core.global.*;
|
||||||
import com.haulmont.cuba.core.global.MetadataBuildInfo;
|
|
||||||
import com.haulmont.cuba.core.global.View;
|
|
||||||
import com.haulmont.cuba.core.global.ViewRepository;
|
|
||||||
import com.haulmont.cuba.core.sys.AbstractMetadata;
|
import com.haulmont.cuba.core.sys.AbstractMetadata;
|
||||||
import com.haulmont.cuba.core.sys.AppContext;
|
import com.haulmont.cuba.core.sys.AppContext;
|
||||||
import com.haulmont.cuba.core.sys.PersistentClassesMetadataLoader;
|
import com.haulmont.cuba.core.sys.PersistentClassesMetadataLoader;
|
||||||
@ -43,6 +41,9 @@ public class MetadataClientImpl extends AbstractMetadata {
|
|||||||
@Inject
|
@Inject
|
||||||
private ServerInfoService serverInfoService;
|
private ServerInfoService serverInfoService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Configuration configuration;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initMetadata() {
|
protected void initMetadata() {
|
||||||
log.info("Initializing metadata");
|
log.info("Initializing metadata");
|
||||||
@ -82,12 +83,16 @@ public class MetadataClientImpl extends AbstractMetadata {
|
|||||||
protected void initViews() {
|
protected void initViews() {
|
||||||
log.info("Initializing views");
|
log.info("Initializing views");
|
||||||
|
|
||||||
viewRepository = new ViewRepository();
|
boolean lazyLoadServerViews = configuration.getConfig(ClientConfig.class).getLazyLoadServerViews();
|
||||||
|
|
||||||
List<View> views = serverInfoService.getViews();
|
viewRepository = new ViewRepositoryClient(lazyLoadServerViews, serverInfoService);
|
||||||
for (View view : views) {
|
|
||||||
MetaClass metaClass = getSession().getClass(view.getEntityClass());
|
if (!lazyLoadServerViews) {
|
||||||
viewRepository.storeView(metaClass, view);
|
List<View> views = serverInfoService.getViews();
|
||||||
|
for (View view : views) {
|
||||||
|
MetaClass metaClass = getSession().getClass(view.getEntityClass());
|
||||||
|
viewRepository.storeView(metaClass, view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String configName = AppContext.getProperty("cuba.viewsConfig");
|
String configName = AppContext.getProperty("cuba.viewsConfig");
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Haulmont Technology Ltd. All Rights Reserved.
|
||||||
|
* Haulmont Technology proprietary and confidential.
|
||||||
|
* Use is subject to license terms.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.haulmont.cuba.client.sys;
|
||||||
|
|
||||||
|
import com.haulmont.chile.core.model.MetaClass;
|
||||||
|
import com.haulmont.cuba.core.app.ServerInfoService;
|
||||||
|
import com.haulmont.cuba.core.global.View;
|
||||||
|
import com.haulmont.cuba.core.global.ViewRepository;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author krivopustov
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class ViewRepositoryClient extends ViewRepository {
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
private boolean lazyLoadServerViews;
|
||||||
|
private ServerInfoService serverInfoService;
|
||||||
|
|
||||||
|
public ViewRepositoryClient(boolean lazyLoadServerViews, ServerInfoService serverInfoService) {
|
||||||
|
this.lazyLoadServerViews = lazyLoadServerViews;
|
||||||
|
this.serverInfoService = serverInfoService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View findView(MetaClass metaClass, String name) {
|
||||||
|
View view = super.findView(metaClass, name);
|
||||||
|
if (view == null && lazyLoadServerViews) {
|
||||||
|
log.trace("Search for view " + metaClass + "/" + name + " on server");
|
||||||
|
view = serverInfoService.getView(metaClass.getJavaClass(), name);
|
||||||
|
if (view != null)
|
||||||
|
storeView(metaClass, view);
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,11 @@
|
|||||||
package com.haulmont.cuba.core.app;
|
package com.haulmont.cuba.core.app;
|
||||||
|
|
||||||
import com.haulmont.chile.core.model.MetaClass;
|
import com.haulmont.chile.core.model.MetaClass;
|
||||||
|
import com.haulmont.cuba.core.entity.Entity;
|
||||||
import com.haulmont.cuba.core.global.Metadata;
|
import com.haulmont.cuba.core.global.Metadata;
|
||||||
import com.haulmont.cuba.core.global.MetadataBuildInfo;
|
import com.haulmont.cuba.core.global.MetadataBuildInfo;
|
||||||
import com.haulmont.cuba.core.global.View;
|
import com.haulmont.cuba.core.global.View;
|
||||||
|
import com.haulmont.cuba.core.global.ViewNotFoundException;
|
||||||
import com.haulmont.cuba.core.sys.MetadataBuildHelper;
|
import com.haulmont.cuba.core.sys.MetadataBuildHelper;
|
||||||
|
|
||||||
import javax.annotation.ManagedBean;
|
import javax.annotation.ManagedBean;
|
||||||
@ -32,14 +34,17 @@ public class ServerInfoServiceBean implements ServerInfoService {
|
|||||||
@Inject
|
@Inject
|
||||||
protected ServerInfoAPI serverInfo;
|
protected ServerInfoAPI serverInfo;
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getReleaseNumber() {
|
public String getReleaseNumber() {
|
||||||
return serverInfo.getReleaseNumber();
|
return serverInfo.getReleaseNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getReleaseTimestamp() {
|
public String getReleaseTimestamp() {
|
||||||
return serverInfo.getReleaseTimestamp();
|
return serverInfo.getReleaseTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public MetadataBuildInfo getMetadataBuildInfo() {
|
public MetadataBuildInfo getMetadataBuildInfo() {
|
||||||
return new MetadataBuildInfo(
|
return new MetadataBuildInfo(
|
||||||
MetadataBuildHelper.getPersistentEntitiesPackages(),
|
MetadataBuildHelper.getPersistentEntitiesPackages(),
|
||||||
@ -75,10 +80,20 @@ public class ServerInfoServiceBean implements ServerInfoService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<View> getViews() {
|
public List<View> getViews() {
|
||||||
return metadata.getViewRepository().getAll();
|
return metadata.getViewRepository().getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(Class<? extends Entity> entityClass, String name) {
|
||||||
|
try {
|
||||||
|
return metadata.getViewRepository().getView(entityClass, name);
|
||||||
|
} catch (ViewNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
return TimeZone.getDefault();
|
return TimeZone.getDefault();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.haulmont.cuba.core.app;
|
package com.haulmont.cuba.core.app;
|
||||||
|
|
||||||
|
import com.haulmont.cuba.core.entity.Entity;
|
||||||
import com.haulmont.cuba.core.global.MetadataBuildInfo;
|
import com.haulmont.cuba.core.global.MetadataBuildInfo;
|
||||||
import com.haulmont.cuba.core.global.View;
|
import com.haulmont.cuba.core.global.View;
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ public interface ServerInfoService {
|
|||||||
|
|
||||||
List<View> getViews();
|
List<View> getViews();
|
||||||
|
|
||||||
|
View getView(Class<? extends Entity> entityClass, String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return time zone used by server application.
|
* Return time zone used by server application.
|
||||||
* Useful for remote clients which may run on machines with another default time zone (like desktop client).
|
* Useful for remote clients which may run on machines with another default time zone (like desktop client).
|
||||||
|
@ -152,7 +152,7 @@ public class ViewRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private View findView(MetaClass metaClass, String name) {
|
protected View findView(MetaClass metaClass, String name) {
|
||||||
Map<String, View> views = storage.get(metaClass);
|
Map<String, View> views = storage.get(metaClass);
|
||||||
View view = (views == null ? null : views.get(name));
|
View view = (views == null ? null : views.get(name));
|
||||||
if (view == null && (name.equals(View.LOCAL) || name.equals(View.MINIMAL))) {
|
if (view == null && (name.equals(View.LOCAL) || name.equals(View.MINIMAL))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user