use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class MetaImpl method getOrderedEntitiesByModules.
@Override
public Map<String, List<Entity>> getOrderedEntitiesByModules(EntityType entityType, String language) {
HashMap<String, List<Entity>> result = new HashMap<>();
for (Module module : getProject().getModulesAndApplication()) {
List<OrderedEntity> entities = new ArrayList<>();
for (Entity entity : module.getEntities()) {
if (entityType == null || entity.getType() == entityType) {
entities.add(new OrderedEntity(entity, getTitle(entity, language)));
}
}
Collections.sort(entities);
result.put(module.getName(), entities.stream().map(e -> e.entity).collect(Collectors.toList()));
}
return result;
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class MetaImpl method getOrderedEntities.
@Override
public List<Entity> getOrderedEntities(EntityType entityType, String language) {
List<OrderedEntity> entities = new ArrayList<>();
for (Module module : getProject().getModulesAndApplication()) {
for (Entity entity : module.getEntities()) {
if (entityType == null || entity.getType() == entityType) {
entities.add(new OrderedEntity(entity, getTitle(entity, language)));
}
}
}
Collections.sort(entities);
return entities.stream().map(e -> e.entity).collect(Collectors.toList());
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class MetaImpl method getQueryIgnoringRoles.
@Override
public Query getQueryIgnoringRoles(String entityName, String queryName) {
Entity entity = getEntity(entityName);
if (entity == null) {
throw Be5Exception.unknownEntity(entityName);
}
Query query = entity.getQueries().get(queryName);
if (query == null) {
throw Be5ErrorCode.UNKNOWN_QUERY.exception(entityName, queryName);
}
return query;
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class DownloadComponent method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
String entity = req.getNonEmpty("_t_");
String ID = req.get("ID");
String typeColumn = req.get("_typeColumn_");
String filenameColumn = req.get("_filenameColumn_");
String dataColumn = req.getNonEmpty("_dataColumn_");
String charsetColumn = req.get("_charsetColumn_");
// String encoding = req.get("_enc_");
boolean download = "yes".equals(req.get("_download_"));
RecordModel record = injector.get(DatabaseModel.class).getEntity(entity).get(ID);
String filename = record.getValueAsString(filenameColumn);
String contentType = record.getValueAsString(typeColumn);
String charset = MoreObjects.firstNonNull(record.getValueAsString(charsetColumn), Charsets.UTF_8.name());
Object data = record.getValue(dataColumn);
InputStream in;
if (data instanceof byte[]) {
in = new ByteArrayInputStream((byte[]) data);
} else // else if (data instanceof Blob)
// {
// in = ((Blob) data).getBinaryStream();
// }
// else if (data instanceof String)
// {
// in = new ByteArrayInputStream(((String) data).getBytes(charset));
// }
{
throw Be5Exception.internal("Unknown data type");
}
HttpServletResponse response = res.getRawResponse();
response.setContentType(contentType + "; charset=" + charset);
if (download) {
response.setHeader("Content-disposition", "attachment; filename=" + UrlEscapers.urlFormParameterEscaper().escape(filename));
} else {
response.setHeader("Content-disposition", "filename=" + UrlEscapers.urlFormParameterEscaper().escape(filename));
}
try {
ByteStreams.copy(in, response.getOutputStream());
} catch (IOException e) {
throw Be5Exception.internal(e);
}
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class Menu method generateEntityOperations.
private List<OperationNode> generateEntityOperations(Entity entity, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds) {
List<OperationNode> operations = new ArrayList<>();
Query allRecords = entity.getQueries().get(DatabaseConstants.ALL_RECORDS_VIEW);
String insertOperationName = INSERT_OPERATION;
if (allRecords != null && allRecords.getOperationNames().getFinalValues().contains(insertOperationName)) {
Operation insertOperation = entity.getOperations().get(insertOperationName);
if (insertOperation != null && meta.isAvailableFor(insertOperation, roles)) {
String title = userAwareMeta.getLocalizedOperationTitle(entity.getName(), insertOperationName);
Action action = ActionUtils.toAction(DatabaseConstants.ALL_RECORDS_VIEW, insertOperation);
OperationId id = withIds ? new OperationId(entity.getName(), insertOperationName) : null;
OperationNode operation = new OperationNode(id, title, action);
operations.add(operation);
}
}
return operations;
}
Aggregations