public Long getResourcePid() { if (myResourcePid == null) { return myResource.getId(); } return myResourcePid; }
protected void validateOkToDelete(List<DeleteConflict> theDeleteConflicts, ResourceTable theEntity, boolean theForValidate) { TypedQuery<ResourceLink> query = myEntityManager.createQuery("SELECT l FROM ResourceLink l WHERE l.myTargetResourcePid = :target_pid", ResourceLink.class); query.setParameter("target_pid", theEntity.getId()); query.setMaxResults(1); List<ResourceLink> resultList = query.getResultList(); if (resultList.isEmpty()) { return; } if (myDaoConfig.isEnforceReferentialIntegrityOnDelete() == false && !theForValidate) { ourLog.debug("Deleting {} resource dependencies which can no longer be satisfied", resultList.size()); myResourceLinkDao.deleteAll(resultList); return; } ResourceLink link = resultList.get(0); IdDt targetId = theEntity.getIdDt(); IdDt sourceId = link.getSourceResource().getIdDt(); String sourcePath = link.getSourcePath(); theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId)); }
protected void expungeHistoricalVersionsOfId(Long theResourceId, AtomicInteger theRemainingCount) { ResourceTable resource = myResourceTableDao.findById(theResourceId).orElseThrow(IllegalArgumentException::new); Pageable page = PageRequest.of(0, theRemainingCount.get()); Slice<Long> versionIds = myResourceHistoryTableDao.findForResourceId(page, resource.getId(), resource.getVersion()); ourLog.debug("Found {} versions of resource {} to expunge", versionIds.getNumberOfElements(), resource.getIdDt().getValue()); for (Long nextVersionId : versionIds) { expungeHistoricalVersion(nextVersionId); if (theRemainingCount.decrementAndGet() <= 0) { return; } } }
@Override public Long getResourceId() { return getId(); }
@Override public void reindex(T theResource, ResourceTable theEntity) { ourLog.debug("Indexing resource {} - PID {}", theEntity.getIdDt().getValue(), theEntity.getId()); if (theResource != null) { CURRENTLY_REINDEXING.put(theResource, Boolean.TRUE); } updateEntity(null, theResource, theEntity, theEntity.getDeleted(), true, false, theEntity.getUpdatedDate(), true, false); if (theResource != null) { CURRENTLY_REINDEXING.put(theResource, null); } }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); Long codeSystemResourcePid = retVal.getId(); TermCodeSystemVersion persCs = myCsvDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid); if (persCs != null) { ourLog.info("Code system version already exists in database"); } else { persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } } return retVal; }
@CoverageIgnore @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof TermCodeSystemVersion)) { return false; } TermCodeSystemVersion other = (TermCodeSystemVersion) obj; if ((myResource.getId() == null) != (other.myResource.getId() == null)) { return false; } else if (!myResource.getId().equals(other.myResource.getId())) { return false; } if (myCodeSystemVersionId == null) { if (other.myCodeSystemVersionId != null) { return false; } } else if (!myCodeSystemVersionId.equals(other.myCodeSystemVersionId)) { return false; } return true; }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); Long codeSystemResourcePid = retVal.getId(); if (retVal.getDeleted() != null) { // deleting } else if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); TermCodeSystemVersion persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } return retVal; }
public void setTargetResource(ResourceTable theTargetResource) { Validate.notNull(theTargetResource); myTargetResource = theTargetResource; myTargetResourcePid = theTargetResource.getId(); myTargetResourceType = theTargetResource.getResourceType(); }
public void setSourceResource(ResourceTable theSourceResource) { mySourceResource = theSourceResource; mySourceResourcePid = theSourceResource.getId(); mySourceResourceType = theSourceResource.getResourceType(); }
@Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); b.append("paramName", getParamName()); b.append("resourceId", getResource().getId()); // TODO: add a field so we don't need to resolve this b.append("value", getValue()); return b.build(); }
@Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); b.append("paramName", getParamName()); b.append("resourceId", getResource().getId()); // TODO: add a field so we don't need to resolve this b.append("valueLow", new InstantDt(getValueLow())); b.append("valueHigh", new InstantDt(getValueHigh())); return b.build(); }
@Override public Long getSubscriptionTablePidForSubscriptionResource(IIdType theId) { ResourceTable entity = readEntityLatestVersion(theId); SubscriptionTable table = mySubscriptionTableDao.findOneByResourcePid(entity.getId()); if (table == null) { return null; } return table.getId(); }
@Override public Long getSubscriptionTablePidForSubscriptionResource(IIdType theId) { ResourceTable entity = readEntityLatestVersion(theId); SubscriptionTable table = mySubscriptionTableDao.findOneByResourcePid(entity.getId()); if (table == null) { return null; } return table.getId(); }
@Override public Long getSubscriptionTablePidForSubscriptionResource(IIdType theId) { ResourceTable entity = readEntityLatestVersion(theId); SubscriptionTable table = mySubscriptionTableDao.findOneByResourcePid(entity.getId()); if (table == null) { return null; } return table.getId(); }
@Override @Transactional(propagation = Propagation.REQUIRED) public IIdType storeNewCodeSystemVersion(CodeSystem theCodeSystemResource, TermCodeSystemVersion theCodeSystemVersion, RequestDetails theRequestDetails, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) { Validate.notBlank(theCodeSystemResource.getUrl(), "theCodeSystemResource must have a URL"); IIdType csId = createOrUpdateCodeSystem(theCodeSystemResource); ResourceTable resource = (ResourceTable) myCodeSystemResourceDao.readEntity(csId); Long codeSystemResourcePid = resource.getId(); ourLog.info("CodeSystem resource has ID: {}", csId.getValue()); theCodeSystemVersion.setResource(resource); storeNewCodeSystemVersion(codeSystemResourcePid, theCodeSystemResource.getUrl(), theCodeSystemResource.getName(), theCodeSystemVersion); myDeferredConceptMaps.addAll(theConceptMaps); myDeferredValueSets.addAll(theValueSets); return csId; }
public ResourceTag(ResourceTable theResourceTable, TagDefinition theTag) { setTag(theTag); setResource(theResourceTable); setResourceId(theResourceTable.getId()); setResourceType(theResourceTable.getResourceType()); }
@Override public List<VersionIndependentConcept> findCodesAbove(String theSystem, String theCode) { TermCodeSystem cs = getCodeSystem(theSystem); if (cs == null) { return findCodesAboveUsingBuiltInSystems(theSystem, theCode); } TermCodeSystemVersion csv = cs.getCurrentVersion(); Set<TermConcept> codes = findCodesAbove(cs.getResource().getId(), csv.getPid(), theCode); return toVersionIndependentConcepts(theSystem, codes); }
@Override public List<VersionIndependentConcept> findCodesBelow(String theSystem, String theCode) { TermCodeSystem cs = getCodeSystem(theSystem); if (cs == null) { return findCodesBelowUsingBuiltInSystems(theSystem, theCode); } TermCodeSystemVersion csv = cs.getCurrentVersion(); Set<TermConcept> codes = findCodesBelow(cs.getResource().getId(), csv.getPid(), theCode); return toVersionIndependentConcepts(theSystem, codes); }