Search in sources :

Example 51 with Entity

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;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 52 with Entity

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());
}
Also used : Operation(com.developmentontheedge.be5.metadata.model.Operation) Arrays(java.util.Arrays) SqlTypeUtils(com.developmentontheedge.sql.format.SqlTypeUtils) ProjectProvider(com.developmentontheedge.be5.api.services.ProjectProvider) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) QueryLink(com.developmentontheedge.be5.api.services.QueryLink) Meta(com.developmentontheedge.be5.api.services.Meta) HashMap(java.util.HashMap) RoleType(com.developmentontheedge.be5.metadata.RoleType) Query(com.developmentontheedge.be5.metadata.model.Query) Function(java.util.function.Function) Be5ErrorCode(com.developmentontheedge.be5.api.exceptions.Be5ErrorCode) ArrayList(java.util.ArrayList) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) Entity(com.developmentontheedge.be5.metadata.model.Entity) EntityItem(com.developmentontheedge.be5.metadata.model.EntityItem) LocalizationElement(com.developmentontheedge.be5.metadata.model.LocalizationElement) BeModelElementSupport(com.developmentontheedge.be5.metadata.model.base.BeModelElementSupport) Utils(com.developmentontheedge.be5.util.Utils) Locale(java.util.Locale) Map(java.util.Map) EntityLocalizations(com.developmentontheedge.be5.metadata.model.EntityLocalizations) StreamSupport(java.util.stream.StreamSupport) LanguageLocalizations(com.developmentontheedge.be5.metadata.model.LanguageLocalizations) Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) Module(com.developmentontheedge.be5.metadata.model.Module) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) DataElementUtils(com.developmentontheedge.be5.metadata.model.DataElementUtils) Localizations(com.developmentontheedge.be5.metadata.model.Localizations) BeCaseInsensitiveCollection(com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection) Predicate(java.util.function.Predicate) Timestamp(java.sql.Timestamp) Set(java.util.Set) Collectors(java.util.stream.Collectors) Date(java.sql.Date) Objects(java.util.Objects) List(java.util.List) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) RoleSet(com.developmentontheedge.be5.metadata.model.RoleSet) SqlColumnType(com.developmentontheedge.be5.metadata.model.SqlColumnType) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Project(com.developmentontheedge.be5.metadata.model.Project) Collections(java.util.Collections) EntityType(com.developmentontheedge.be5.metadata.model.EntityType) Entity(com.developmentontheedge.be5.metadata.model.Entity) ArrayList(java.util.ArrayList) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 53 with Entity

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;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query)

Example 54 with Entity

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RecordModel(com.developmentontheedge.be5.databasemodel.RecordModel) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException)

Example 55 with Entity

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;
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)36 Query (com.developmentontheedge.be5.metadata.model.Query)19 Module (com.developmentontheedge.be5.metadata.model.Module)16 Project (com.developmentontheedge.be5.metadata.model.Project)16 Test (org.junit.Test)11 Path (java.nio.file.Path)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)7 Operation (com.developmentontheedge.be5.metadata.model.Operation)7 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)7 Meta (com.developmentontheedge.be5.api.services.Meta)4 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)4 Map (java.util.Map)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)3 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2