Search in sources :

Example 1 with AbstractViewRepository

use of com.haulmont.cuba.core.sys.AbstractViewRepository in project cuba by cuba-platform.

the class DomainDescriptionServiceBean method getDomainDescription.

@Override
public String getDomainDescription() {
    List<View> views = ((AbstractViewRepository) viewRepository).getAll();
    List<MetaClassRepresentation> classes = new ArrayList<>();
    List<TemplateHashModel> enums = new ArrayList<>();
    Set<String> addedEnums = new HashSet<>();
    Set<MetaClass> metas = new HashSet<>(metadataTools.getAllPersistentMetaClasses());
    metas.addAll(metadataTools.getAllEmbeddableMetaClasses());
    for (MetaClass meta : metas) {
        if (metadata.getExtendedEntities().getExtendedClass(meta) != null)
            continue;
        if (!readPermitted(meta))
            continue;
        List<View> metaClassViews = new ArrayList<>();
        for (View view : views) {
            if (view.getEntityClass().equals(meta.getJavaClass())) {
                metaClassViews.add(view);
            }
        }
        MetaClassRepresentation rep = new MetaClassRepresentation(meta, metaClassViews);
        classes.add(rep);
        for (MetaClassRepresentation.MetaClassRepProperty metaProperty : rep.getProperties()) {
            TemplateHashModel enumValues = metaProperty.getEnumValues();
            if (enumValues != null) {
                if (!addedEnums.contains(metaProperty.getJavaType())) {
                    addedEnums.add(metaProperty.getJavaType());
                    enums.add(enumValues);
                }
            }
        }
    }
    Collections.sort(classes, new Comparator<MetaClassRepresentation>() {

        @Override
        public int compare(MetaClassRepresentation o1, MetaClassRepresentation o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Collections.sort(enums, new Comparator<TemplateHashModel>() {

        @Override
        public int compare(TemplateHashModel o1, TemplateHashModel o2) {
            try {
                return o1.get("name").toString().compareTo(o2.get("name").toString());
            } catch (TemplateModelException e) {
                return 0;
            }
        }
    });
    Map<String, Object> values = new HashMap<>();
    values.put("knownEntities", classes);
    String[] availableTypes = getAvailableBasicTypes();
    values.put("availableTypes", availableTypes);
    values.put("enums", enums);
    String template = resources.getResourceAsString("/com/haulmont/cuba/core/app/domain/DomainDescription.ftl");
    return TemplateHelper.processTemplate(template, values);
}
Also used : AbstractViewRepository(com.haulmont.cuba.core.sys.AbstractViewRepository) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 2 with AbstractViewRepository

use of com.haulmont.cuba.core.sys.AbstractViewRepository in project cuba by cuba-platform.

the class ViewRepositoryOverwriteTest method setUp.

@Before
public void setUp() throws Exception {
    repository = cont.metadata().getViewRepository();
    InputStream stream = ViewRepositoryTest.class.getResourceAsStream("test-overwrite.view.xml");
    ((AbstractViewRepository) repository).deployViews(stream);
}
Also used : AbstractViewRepository(com.haulmont.cuba.core.sys.AbstractViewRepository) InputStream(java.io.InputStream) Before(org.junit.Before)

Example 3 with AbstractViewRepository

use of com.haulmont.cuba.core.sys.AbstractViewRepository in project cuba by cuba-platform.

the class ViewRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    repository = cont.metadata().getViewRepository();
    InputStream stream = ViewRepositoryTest.class.getResourceAsStream("test.view.xml");
    ((AbstractViewRepository) repository).deployViews(stream);
}
Also used : AbstractViewRepository(com.haulmont.cuba.core.sys.AbstractViewRepository) InputStream(java.io.InputStream) Before(org.junit.Before)

Example 4 with AbstractViewRepository

use of com.haulmont.cuba.core.sys.AbstractViewRepository in project cuba by cuba-platform.

the class DataServiceController method deployViews.

@RequestMapping(value = "/api/deployViews", method = RequestMethod.POST)
public void deployViews(@RequestParam(value = "s") String sessionId, @RequestBody String requestContent, HttpServletRequest request, HttpServletResponse response) throws IOException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    if (!connect(sessionId, response))
        return;
    try {
        ViewRepository viewRepository = metadata.getViewRepository();
        ((AbstractViewRepository) viewRepository).deployViews(new StringReader(requestContent));
    } catch (Throwable e) {
        sendError(request, response, e);
    } finally {
        authentication.end();
    }
}
Also used : AbstractViewRepository(com.haulmont.cuba.core.sys.AbstractViewRepository) AbstractViewRepository(com.haulmont.cuba.core.sys.AbstractViewRepository) StringReader(java.io.StringReader)

Aggregations

AbstractViewRepository (com.haulmont.cuba.core.sys.AbstractViewRepository)4 InputStream (java.io.InputStream)2 Before (org.junit.Before)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 StringReader (java.io.StringReader)1