Search in sources :

Example 1 with MutableClassAccessor

use of com.manydesigns.elements.reflection.MutableClassAccessor in project Portofino by ManyDesigns.

the class TablesAction method getAnnotations.

@Path("{db}/{schema}/{table}/{column}/annotations/{typeName}")
@GET
public String getAnnotations(@PathParam("db") String db, @PathParam("schema") String schema, @PathParam("table") String tableName, @PathParam("column") String columnName, @PathParam("typeName") String typeName) throws ClassNotFoundException {
    Column column = DatabaseLogic.findColumnByName(persistence.getModel(), db, schema, tableName, columnName);
    if (column == null) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    Class<?> type = getColumnType(column, typeName);
    MutableClassAccessor classAccessor = getApplicableAnnotations(type);
    JSONStringer jsonStringer = new JSONStringer();
    jsonStringer.object();
    jsonStringer.key("classAccessor");
    ReflectionUtil.classAccessorToJson(classAccessor, jsonStringer);
    jsonStringer.key("annotations");
    jsonStringer.object();
    column.getAnnotations().forEach(a -> {
        String annType = a.getType();
        if (DATE_FORMAT.equals(annType)) {
            jsonStringer.key("dateFormat");
        } else if (DECIMAL_FORMAT.equals(annType)) {
            jsonStringer.key("decimalFormat");
        } else if (FIELD_SIZE.equals(annType)) {
            jsonStringer.key("fieldSize");
        } else if (FILE_BLOB.equals(annType)) {
            jsonStringer.key("fileBlob");
        } else if (HIGHLIGHT_LINKS.equals(annType)) {
            jsonStringer.key("highlightLinks");
        } else if (MIN_INT_VALUE.equals(annType)) {
            jsonStringer.key("minValue");
        } else if (MIN_DECIMAL_VALUE.equals(annType)) {
            jsonStringer.key("minValue");
        } else if (MAX_INT_VALUE.equals(annType)) {
            jsonStringer.key("maxValue");
        } else if (MAX_DECIMAL_VALUE.equals(annType)) {
            jsonStringer.key("maxValue");
        } else if (MULTILINE.equals(annType)) {
            jsonStringer.key("typeOfContent");
            jsonStringer.object();
            jsonStringer.key("v").value(annType);
            jsonStringer.key("l").value("Multiline");
            jsonStringer.key("s").value(true);
            jsonStringer.endObject();
            return;
        } else if (REGEXP.equals(annType)) {
            jsonStringer.key("regexp");
            jsonStringer.value(a.getProperty("value").getValue());
            return;
        } else if (RICH_TEXT.equals(annType)) {
            jsonStringer.key("typeOfContent");
            jsonStringer.object();
            jsonStringer.key("v").value(annType);
            jsonStringer.key("l").value("Rich text");
            jsonStringer.key("s").value(true);
            jsonStringer.endObject();
            return;
        } else if (STRING_FORMAT.containsKey(annType)) {
            jsonStringer.key("stringFormat");
            jsonStringer.object();
            jsonStringer.key("v").value(annType);
            jsonStringer.key("l").value(STRING_FORMAT.get(annType));
            jsonStringer.key("s").value(true);
            jsonStringer.endObject();
            return;
        } else if (DATABASE_BLOB.equals(annType)) {
            jsonStringer.key("databaseBlobContentTypeProperty").value(a.getProperty("contentTypeProperty").getValue());
            jsonStringer.key("databaseBlobFileNameProperty").value(a.getProperty("fileNameProperty").getValue());
            jsonStringer.key("databaseBlobTimestampProperty").value(a.getProperty("timestampProperty").getValue());
            return;
        } else {
            jsonStringer.key("annotation");
            jsonStringer.object();
            jsonStringer.key("type").value(annType);
            jsonStringer.key("properties");
            jsonStringer.array();
            a.getProperties().forEach(p -> jsonStringer.key(p.getName()).value(p.getValue()));
            jsonStringer.endArray();
            jsonStringer.endObject();
            return;
        }
        if (a.getProperties().size() > 1) {
            jsonStringer.object();
            for (Property p : a.getProperties()) {
                jsonStringer.key(p.getName()).value(p.getValue());
            }
            jsonStringer.endObject();
        } else {
            jsonStringer.value(a.getProperties().get(0).getValue());
        }
    });
    jsonStringer.endObject();
    jsonStringer.endObject();
    return jsonStringer.toString();
}
Also used : ColumnAndAnnotations(com.manydesigns.portofino.upstairs.actions.database.tables.support.ColumnAndAnnotations) Persistence(com.manydesigns.portofino.persistence.Persistence) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) AbstractResourceAction(com.manydesigns.portofino.resourceactions.AbstractResourceAction) MutablePropertyAccessor(com.manydesigns.elements.reflection.MutablePropertyAccessor) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) AbstractCrudAction(com.manydesigns.portofino.resourceactions.crud.AbstractCrudAction) com.manydesigns.elements.annotations(com.manydesigns.elements.annotations) BigDecimal(java.math.BigDecimal) Form(com.manydesigns.elements.forms.Form) Property(com.manydesigns.portofino.model.Property) MediaType(javax.ws.rs.core.MediaType) EntityPermissions(com.manydesigns.portofino.resourceactions.crud.security.EntityPermissions) JSONStringer(org.json.JSONStringer) MapKeyValueAccessor(com.manydesigns.elements.MapKeyValueAccessor) Permissions(com.manydesigns.portofino.actions.Permissions) BigInteger(java.math.BigInteger) Annotation(com.manydesigns.portofino.model.Annotation) RequiresAdministrator(com.manydesigns.portofino.security.RequiresAdministrator) SecurityLogic(com.manydesigns.portofino.security.SecurityLogic) Logger(org.slf4j.Logger) DisplayMode(com.manydesigns.elements.options.DisplayMode) FileSystemException(org.apache.commons.vfs2.FileSystemException) MutableClassAccessor(com.manydesigns.elements.reflection.MutableClassAccessor) Group(com.manydesigns.portofino.actions.Group) com.manydesigns.portofino.model.database(com.manydesigns.portofino.model.database) FileObject(org.apache.commons.vfs2.FileObject) RequestMessages(com.manydesigns.elements.messages.RequestMessages) TableInfo(com.manydesigns.portofino.upstairs.actions.support.TableInfo) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) SelectImpl(com.manydesigns.elements.annotations.impl.SelectImpl) SearchDisplayMode(com.manydesigns.elements.options.SearchDisplayMode) FormBuilder(com.manydesigns.elements.forms.FormBuilder) FileType(org.apache.commons.vfs2.FileType) EntityPermissionsChecks(com.manydesigns.portofino.resourceactions.crud.security.EntityPermissionsChecks) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) NotNull(org.jetbrains.annotations.NotNull) ReflectionUtil(com.manydesigns.elements.util.ReflectionUtil) ArrayUtils(org.apache.commons.lang.ArrayUtils) BeanUtils(org.springframework.beans.BeanUtils) JSONStringer(org.json.JSONStringer) Property(com.manydesigns.portofino.model.Property) MutableClassAccessor(com.manydesigns.elements.reflection.MutableClassAccessor)

Example 2 with MutableClassAccessor

use of com.manydesigns.elements.reflection.MutableClassAccessor in project Portofino by ManyDesigns.

the class TablesAction method getApplicableAnnotations.

@NotNull
public MutableClassAccessor getApplicableAnnotations(Class type) {
    MutableClassAccessor classAccessor = new MutableClassAccessor();
    if (type == null) {
        return classAccessor;
    }
    if (Number.class.isAssignableFrom(type)) {
        classAccessor.addProperty(new MutablePropertyAccessor("fieldSize", Integer.class));
        classAccessor.addProperty(new MutablePropertyAccessor("minValue", BigDecimal.class));
        classAccessor.addProperty(new MutablePropertyAccessor("maxValue", BigDecimal.class));
        classAccessor.addProperty(new MutablePropertyAccessor("decimalFormat", String.class));
    } else if (String.class.equals(type)) {
        classAccessor.addProperty(new MutablePropertyAccessor("fieldSize", Integer.class));
        classAccessor.addProperty(new MutablePropertyAccessor("regexp", String.class));
        classAccessor.addProperty(new MutablePropertyAccessor("highlightLinks", Boolean.class));
        classAccessor.addProperty(new MutablePropertyAccessor("fileBlob", Boolean.class));
        SelectImpl select = new SelectImpl(DisplayMode.DROPDOWN, SearchDisplayMode.DROPDOWN, new String[] { EMAIL, PASSWORD, CAP, PARTITA_IVA, CODICE_FISCALE, PHONE, ENCRYPTED }, new String[] { "Email", "Password", "CAP/ZIP", "Partita IVA", "Codice Fiscale", "Phone", "Encrypted" }, true);
        classAccessor.addProperty(new MutablePropertyAccessor("stringFormat", String.class).configureAnnotation(select));
        select = new SelectImpl(DisplayMode.DROPDOWN, SearchDisplayMode.DROPDOWN, new String[] { MULTILINE, RICH_TEXT }, new String[] { "Multiline", "Rich text" }, true);
        classAccessor.addProperty(new MutablePropertyAccessor("typeOfContent", String.class).configureAnnotation(select));
    } else if (Date.class.isAssignableFrom(type)) {
        classAccessor.addProperty(new MutablePropertyAccessor("fieldSize", Integer.class));
        classAccessor.addProperty(new MutablePropertyAccessor("dateFormat", String.class));
    } else if (byte[].class.isAssignableFrom(type)) {
        classAccessor.addProperty(new MutablePropertyAccessor("databaseBlobContentTypeProperty", String.class));
        classAccessor.addProperty(new MutablePropertyAccessor("databaseBlobFileNameProperty", String.class));
        classAccessor.addProperty(new MutablePropertyAccessor("databaseBlobTimestampProperty", String.class));
    }
    return classAccessor;
}
Also used : BigInteger(java.math.BigInteger) SelectImpl(com.manydesigns.elements.annotations.impl.SelectImpl) MutablePropertyAccessor(com.manydesigns.elements.reflection.MutablePropertyAccessor) BigDecimal(java.math.BigDecimal) MutableClassAccessor(com.manydesigns.elements.reflection.MutableClassAccessor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SelectImpl (com.manydesigns.elements.annotations.impl.SelectImpl)2 MutableClassAccessor (com.manydesigns.elements.reflection.MutableClassAccessor)2 MutablePropertyAccessor (com.manydesigns.elements.reflection.MutablePropertyAccessor)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 NotNull (org.jetbrains.annotations.NotNull)2 MapKeyValueAccessor (com.manydesigns.elements.MapKeyValueAccessor)1 com.manydesigns.elements.annotations (com.manydesigns.elements.annotations)1 Form (com.manydesigns.elements.forms.Form)1 FormBuilder (com.manydesigns.elements.forms.FormBuilder)1 RequestMessages (com.manydesigns.elements.messages.RequestMessages)1 DisplayMode (com.manydesigns.elements.options.DisplayMode)1 SearchDisplayMode (com.manydesigns.elements.options.SearchDisplayMode)1 ReflectionUtil (com.manydesigns.elements.util.ReflectionUtil)1 Group (com.manydesigns.portofino.actions.Group)1 Permissions (com.manydesigns.portofino.actions.Permissions)1 Annotation (com.manydesigns.portofino.model.Annotation)1 Property (com.manydesigns.portofino.model.Property)1 com.manydesigns.portofino.model.database (com.manydesigns.portofino.model.database)1 Persistence (com.manydesigns.portofino.persistence.Persistence)1