public RecordLinkWeb loadRecordLinks( EntityWeb entityModel, Long leftRecordId, Long rightRecordId, String state) throws Exception { log.debug("Received request to retrieve a list of entity record links."); authenticateCaller(); try { RecordQueryService entityInstanceService = Context.getRecordQueryService(); EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService(); Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId()); List<RecordLink> records = entityInstanceService.loadRecordLinks( entityDef, rightRecordId, RecordLinkState.fromString(state)); for (RecordLink record : records) { // loadRecordLinks with left and right Records RecordLink recordlLink = entityInstanceService.loadRecordLink(entityDef, record.getRecordLinkId()); if (recordlLink.getLeftRecord().getRecordId() == leftRecordId || recordlLink.getRightRecord().getRecordId() == leftRecordId) { RecordLinkWeb recordlLinkWeb = ModelTransformer.mapToRecordLink(recordlLink, RecordLinkWeb.class, true); return recordlLinkWeb; } } return null; } catch (Throwable t) { log.error("Failed to execute: " + t.getMessage(), t); throw new RuntimeException(t); } }
public List<RecordLinkWeb> loadRecordLinks( EntityWeb entityModel, String state, int firstResult, int maxResults) throws Exception { log.debug("Received request to retrieve a list of entity record links."); authenticateCaller(); try { RecordQueryService entityInstanceService = Context.getRecordQueryService(); EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService(); Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId()); List<RecordLink> records = entityInstanceService.loadRecordLinks( entityDef, RecordLinkState.fromString(state), firstResult, maxResults); List<RecordLinkWeb> dtos = new java.util.ArrayList<RecordLinkWeb>(records.size()); for (RecordLink record : records) { // loadRecordLinks without left and right Records RecordLinkWeb dto = ModelTransformer.mapToRecordLink(record, RecordLinkWeb.class, false); dtos.add(dto); } return dtos; } catch (Throwable t) { log.error("Failed to execute: " + t.getMessage(), t); throw new RuntimeException(t); } }
@Override public RecordLinksListWeb loadRecordLinksPaged(RecordSearchCriteriaWeb searchCriteria) throws Exception { log.debug("Get Record Links"); authenticateCaller(); try { RecordQueryService entityInstanceService = Context.getRecordQueryService(); EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService(); EntityWeb entityModel = searchCriteria.getEntityModel(); Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId()); int offset = searchCriteria.getFirstResult(); int pageSize = searchCriteria.getMaxResults(); String state = searchCriteria.getSearchMode().substring(0, 1); // Get total count Long totalCount = searchCriteria.getTotalCount(); if (totalCount == 0) { totalCount = entityInstanceService.getRecordLinkCount(entityDef, RecordLinkState.fromString(state)); } // get List of Record List<RecordLink> recordLinks = entityInstanceService.loadRecordLinks( entityDef, RecordLinkState.fromString(state), offset, pageSize); List<RecordLinkWeb> dtos = new java.util.ArrayList<RecordLinkWeb>(recordLinks.size()); for (RecordLink record : recordLinks) { // loadRecordLinks without left and right Records RecordLinkWeb dto = ModelTransformer.mapToRecordLink(record, RecordLinkWeb.class, false); dtos.add(dto); } RecordLinksListWeb recordList = new RecordLinksListWeb(); recordList.setTotalCount(totalCount); recordList.setRecordLinks(dtos); return recordList; } catch (Exception e) { log.error("Failed while trying to get audit events: " + e, e); } return null; }