RecordsService (Java)

RecordsService — a service for working with abstract records whose source can be any DAO.

There are four operations that can be performed on records:

Methods: query, queryOne

A RecordsQuery containing search parameters is always passed for searching records. In addition to the simplest method with a single RecordsQuery parameter, there are also variants with combined search and attribute querying.

recordsService.queryOne(
  RecordsQuery.create()
    .withSourceId("emodel/person")
    .withLanguage(PredicateService.LANGUAGE_PREDICATE)
    .withQuery(Predicates.and(
            Predicates.eq("city", "Tomsk"),
            Predicates.eq("organization", "Citeck")))
    .withConsistency(Consistency.EVENTUAL)
    .addSort(new SortBy("_created", true))
    .build());
recordsService.query(RecordsQuery.create()
    .withSourceId("edi/edi-inbound-main-document")
    .withLanguage(PredicateService.LANGUAGE_PREDICATE)
    .withQuery(Predicates.and(
            Predicates.eq("type", "emodel/type@testip-inboundPackage"),
            Predicates.eq("testip:isNeedSendToVim", true),
            Predicates.not(
                    Predicates.eq("testip:isAlreadySentToVim", true)
            )
    ))
    .withConsistency(Consistency.EVENTUAL)
    .build());
  • .withLanguage — specifies the query language;

  • .withQuery — the query itself;

  • .withConsistency — Consistency. Possible values: EVENTUAL, TRANSACTIONAL, DEFAULT, TRANSACTIONAL_IF_POSSIBLE;

  • .addSort — specifies the field to sort by;

  • .build() — builds the query.

Output:

  • with query we get RecsQueryRes<RecordRef>

  • with queryOne we get RecordRef

Methods: getAtt, getAtts

recordsService.getAtt(documentRef, "eint:ediProviderType?str").asText();
  • documentRef — the record being accessed

  • “eint:ediProviderType?str” — the parameter we want to retrieve

List<ObjPropertyClass> list = recordsService.getAtt(documentRef, "objProperty[]?json").asList(ObjPropertyClass.class);
RecordAtts recordAtts = recordsService.getAtts(RecordRef.valueOf(nodeRef.toString()),
      Collections.singletonMap("assocId", name + "[]?id"));

There are two levels of abstraction for retrieving attributes:

DTO Class > Attributes

  • DTO Class - класс, который используется для генерации списка аттрибутов для формирования схемы и запроса атрибутов из DAO. После получения всех данных из DAO идет создание инстансов переданного DTO класса и наполнение его данными с помощью библиотеки jackson. Список аттрибутов формируется либо из названий полей, либо можно добавить аннотацию AttName для указания атрибута вручную.

  • Attributes - аттрибуты записи в чистом виде. Есть варианты с одним атрибутом, списком атрибутов или набором ключ→значение (Map).

Each DAO decides on its own whether to create or edit the received record. If a record with an empty identifier arrives at the DAO, it is a command to create a new record.

RecordAtts recordAtts = new RecordAtts();
recordAtts.setId(recordRef);
recordAtts.setAtt("testdl:isOutboundPackageSyncNeeded", false);
recordsService.mutate(recordAtts);

To update a record, you must specify .setId() for the record that needs to be modified.

RecordAtts recordAtts = new RecordAtts();
recordAtts.setAtt(RecordConstants.ATT_TYPE, "emodel/type@testdl-routeTemplateItem");
recordAtts.setAtt(RecordConstants.ATT_PARENT, "eproc/routeTemplate@c897a06d-e1b5-4564-9966-762124399dfd");
recordAtts.setAtt(RecordConstants.ATT_PARENT_ATT, "routes");
recordsService.mutate(recordAtts);

When creating a new record, the setId() parameter is not specified.

Если при мутации указать атрибут __disableAudit=true (константа DbRecordsControlAtts.DISABLE_AUDIT), то поля _creator, _created, _modifier, _modified заполняться автоматически не будут. Если эти поля установить вручную, то в БД попадут именно они.

For creator and modifier, both the username and the full user ref are acceptable.

Атрибут __disableAudit допустимо проставлять только в контексте системы (runAsSystem).

recordsService.delete(routeTemplate);
  • RecordRef routeTemplate — the record to be deleted