Search in sources :

Example 1 with QueryDO

use of de.ids_mannheim.korap.entity.QueryDO in project Kustvakt by KorAP.

the class QueryReferenceRewrite method findQueryRef.

private void findQueryRef(String username, KoralNode koralNode) throws KustvaktException {
    if (koralNode.has("@type") && koralNode.get("@type").equals("koral:queryRef")) {
        if (!koralNode.has("ref")) {
            throw new KustvaktException(de.ids_mannheim.korap.util.StatusCodes.MISSING_QUERY_REFERENCE, "ref is not found");
        } else {
            String queryRefName = koralNode.get("ref");
            String queryRefOwner = "system";
            if (queryRefName.contains("/")) {
                String[] names = queryRefName.split("/");
                if (names.length == 2) {
                    queryRefOwner = names[0];
                    queryRefName = names[1];
                }
            }
            QueryDO qr = service.searchQueryByName(username, queryRefName, queryRefOwner, QueryType.QUERY);
            if (qr == null) {
                throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND, "Query reference " + queryRefName + " is not found.", String.valueOf(queryRefName));
            }
            // TODO:
            // checkVCAcess(q, username);
            JsonNode qref = JsonUtils.readTree(qr.getKoralQuery());
            ;
            rewriteQuery(qref, koralNode);
        }
    } else if (koralNode.has("operands")) {
        KoralNode operands = koralNode.at("/operands");
        for (int i = 0; i < operands.size(); i++) {
            KoralNode operand = operands.get(i);
            this.findQueryRef(username, operand);
            operand.buildRewrites();
        }
    }
}
Also used : KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) QueryDO(de.ids_mannheim.korap.entity.QueryDO) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with QueryDO

use of de.ids_mannheim.korap.entity.QueryDO in project Kustvakt by KorAP.

the class VirtualCorpusRewrite method findVCRef.

private void findVCRef(String username, KoralNode koralNode) throws KustvaktException {
    if (koralNode.has("@type") && koralNode.get("@type").equals("koral:docGroupRef")) {
        if (!koralNode.has("ref")) {
            throw new KustvaktException(StatusCodes.MISSING_VC_REFERENCE, "ref is not found");
        } else {
            String vcName = koralNode.get("ref");
            String vcOwner = "system";
            boolean ownerExist = false;
            if (vcName.contains("/")) {
                String[] names = vcName.split("/");
                if (names.length == 2) {
                    vcOwner = names[0];
                    vcName = names[1];
                    ownerExist = true;
                }
            }
            String vcInCaching = config.getVcInCaching();
            if (vcName.equals(vcInCaching)) {
                throw new KustvaktException(de.ids_mannheim.korap.exceptions.StatusCodes.CACHING_VC, "VC is currently busy and unaccessible due to " + "caching process", koralNode.get("ref"));
            }
            QueryDO vc = queryService.searchQueryByName(username, vcName, vcOwner, QueryType.VIRTUAL_CORPUS);
            if (!vc.isCached()) {
                rewriteVC(vc, koralNode);
            } else // required for named-vc since they are stored by filenames in the cache
            if (ownerExist) {
                removeOwner(vc.getKoralQuery(), vcOwner, koralNode);
            }
        }
    } else if (koralNode.has("operands")) {
        KoralNode operands = koralNode.at("/operands");
        for (int i = 0; i < operands.size(); i++) {
            KoralNode operand = operands.get(i);
            findVCRef(username, operand);
            operand.buildRewrites();
        }
    }
}
Also used : KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) QueryDO(de.ids_mannheim.korap.entity.QueryDO)

Example 3 with QueryDO

use of de.ids_mannheim.korap.entity.QueryDO in project Kustvakt by KorAP.

the class QueryService method createQueryDtos.

private ArrayList<QueryDto> createQueryDtos(List<QueryDO> queryList, QueryType queryType) throws KustvaktException {
    ArrayList<QueryDto> dtos = new ArrayList<>(queryList.size());
    QueryDO query;
    Iterator<QueryDO> i = queryList.iterator();
    while (i.hasNext()) {
        query = i.next();
        // String json = query.getKoralQuery();
        String statistics = null;
        // if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
        // statistics = krill.getStatistics(json);
        // }
        QueryDto dto = converter.createQueryDto(query, statistics);
        dtos.add(dto);
    }
    return dtos;
}
Also used : QueryDto(de.ids_mannheim.korap.dto.QueryDto) QueryDO(de.ids_mannheim.korap.entity.QueryDO) ArrayList(java.util.ArrayList)

Example 4 with QueryDO

use of de.ids_mannheim.korap.entity.QueryDO in project Kustvakt by KorAP.

the class QueryService method retrieveQueryByName.

public QueryDto retrieveQueryByName(String username, String queryName, String createdBy, QueryType queryType) throws KustvaktException {
    QueryDO query = searchQueryByName(username, queryName, createdBy, queryType);
    // String json = query.getKoralQuery();
    String statistics = null;
    // start));
    return converter.createQueryDto(query, statistics);
}
Also used : QueryDO(de.ids_mannheim.korap.entity.QueryDO)

Example 5 with QueryDO

use of de.ids_mannheim.korap.entity.QueryDO in project Kustvakt by KorAP.

the class QueryService method handlePutRequest.

public Status handlePutRequest(String username, String queryCreator, String queryName, QueryJson queryJson) throws KustvaktException {
    verifyUsername(username, queryCreator);
    QueryDO query = queryDao.retrieveQueryByName(queryName, queryCreator);
    if (query == null) {
        storeQuery(queryJson, queryName, queryCreator, username);
        return Status.CREATED;
    } else {
        editQuery(query, queryJson, queryName, username);
        return Status.NO_CONTENT;
    }
}
Also used : QueryDO(de.ids_mannheim.korap.entity.QueryDO)

Aggregations

QueryDO (de.ids_mannheim.korap.entity.QueryDO)35 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)14 Predicate (javax.persistence.criteria.Predicate)12 KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)11 Query (javax.persistence.Query)11 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)11 QueryAccess (de.ids_mannheim.korap.entity.QueryAccess)9 UserGroup (de.ids_mannheim.korap.entity.UserGroup)9 Test (org.junit.Test)8 SpringJerseyTest (de.ids_mannheim.korap.config.SpringJerseyTest)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 NoResultException (javax.persistence.NoResultException)4 ArrayList (java.util.ArrayList)3 QueryDto (de.ids_mannheim.korap.dto.QueryDto)2 UserGroupMember (de.ids_mannheim.korap.entity.UserGroupMember)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 DocBits (de.ids_mannheim.korap.collection.DocBits)1 PredefinedRole (de.ids_mannheim.korap.constant.PredefinedRole)1 QueryAccessDto (de.ids_mannheim.korap.dto.QueryAccessDto)1