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();
}
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;
}
Aggregations