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