use of com.manydesigns.portofino.model.Annotation in project Portofino by ManyDesigns.
the class PersistenceTest method testAnnotations.
public void testAnnotations() {
Session session = persistence.getSession("hibernatetest");
try {
session.createNamedQuery("all_questions", Map.class).list();
fail("Exception expected");
} catch (Exception e) {
}
Table table = DatabaseLogic.findTableByName(persistence.getModel(), "hibernatetest", "PUBLIC", "DOMANDA");
assertNotNull(table);
Annotation nq = new Annotation(table, "javax.persistence.NamedQuery");
nq.setProperties(Arrays.asList(new Property("name", "all_questions"), new Property("query", "from domanda")));
table.getAnnotations().add(nq);
persistence.initModel();
session = persistence.getSession("hibernatetest");
List<Object> allQuestions = session.createNamedQuery("all_questions", Object.class).list();
assertEquals(2, allQuestions.size());
}
use of com.manydesigns.portofino.model.Annotation in project Portofino by ManyDesigns.
the class DatabaseSyncer method copyAnnotations.
protected void copyAnnotations(Annotated source, Annotated target) {
for (Annotation ann : source.getAnnotations()) {
Annotation annCopy = new Annotation();
annCopy.setParent(target);
annCopy.setType(ann.getType());
annCopy.setValues(ann.getValues());
annCopy.setProperties(ann.getProperties());
target.getAnnotations().add(annCopy);
}
}
use of com.manydesigns.portofino.model.Annotation in project Portofino by ManyDesigns.
the class TablesAction method saveTable.
@Path("{db}/{schema}/{table}")
@PUT
public void saveTable(@PathParam("db") String db, @PathParam("schema") String schema, @PathParam("table") String tableName, TableInfo tableInfo) throws Exception {
Table table = tableInfo.table;
Table existing = DatabaseLogic.findTableByName(persistence.getModel(), db, schema, tableName);
if (existing == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
existing.setEntityName(table.getEntityName());
existing.setJavaClass(table.getJavaClass());
existing.setShortName(table.getShortName());
for (Column column : table.getColumns()) {
Column c2 = DatabaseLogic.findColumnByName(existing, column.getColumnName());
BeanUtils.copyProperties(column, c2);
c2.setTable(existing);
}
existing.getColumns().sort(Comparator.comparingInt(c -> table.getColumns().indexOf(DatabaseLogic.findColumnByName(table, c.getColumnName()))));
existing.getSelectionProviders().clear();
existing.getSelectionProviders().addAll(table.getSelectionProviders());
existing.getSelectionProviders().forEach(sp -> {
sp.setFromTable(existing);
sp.getReferences().forEach(r -> r.setOwner(sp));
});
existing.removeAnnotation(EntityPermissions.class);
Permissions permissions = tableInfo.permissions;
if (permissions != null) {
permissions.init();
String allGroup = SecurityLogic.getAllGroup(portofinoConfiguration);
List<String> create = new ArrayList<>();
List<String> read = new ArrayList<>();
List<String> update = new ArrayList<>();
List<String> delete = new ArrayList<>();
permissions.getActualPermissions().forEach((group, perms) -> {
String actualGroup = group.equals(allGroup) ? "*" : group;
if (perms.contains(AbstractCrudAction.PERMISSION_CREATE)) {
create.add(actualGroup);
}
if (perms.contains(AbstractCrudAction.PERMISSION_READ)) {
read.add(actualGroup);
}
if (perms.contains(AbstractCrudAction.PERMISSION_EDIT)) {
update.add(actualGroup);
}
if (perms.contains(AbstractCrudAction.PERMISSION_DELETE)) {
delete.add(actualGroup);
}
});
if (create.size() == 1 && create.contains("*") && read.size() == 1 && read.contains("*") && update.size() == 1 && update.contains("*") && delete.size() == 1 && delete.contains("*")) {
// Don't add the annotation: permissions have their default values
} else {
Annotation newAnn = new Annotation(EntityPermissions.class);
newAnn.setProperty("create", StringUtils.join(create, ", "));
newAnn.setProperty("read", StringUtils.join(read, ", "));
newAnn.setProperty("update", StringUtils.join(update, ", "));
newAnn.setProperty("delete", StringUtils.join(delete, ", "));
existing.addAnnotation(newAnn);
}
}
persistence.initModel();
persistence.saveXmlModel();
}
Aggregations