@Override public void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel) { StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theId); if (entity == null) { throw new ResourceNotFoundException(theId); } for (BaseTag next : new ArrayList<>(entity.getTags())) { if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) && ObjectUtil.equals(next.getTag().getSystem(), theScheme) && ObjectUtil.equals(next.getTag().getCode(), theTerm)) { return; } } entity.setHasTags(true); TagDefinition def = getTagOrNull(TagTypeEnum.TAG, theScheme, theTerm, theLabel); if (def != null) { BaseTag newEntity = entity.addTag(def); if (newEntity.getTagId() == null) { myEntityManager.persist(newEntity); myEntityManager.merge(entity); } } ourLog.debug("Processed addTag {}/{} on {} in {}ms", theScheme, theTerm, theId, w.getMillisAndRestart()); }
try { BaseHasResource entity = myCallingDao.readEntity(valueAsId); if (entity.getDeleted() == null) { orPids.add(entity.getId());
private void validateGivenIdIsAppropriateToRetrieveResource(IIdType theId, BaseHasResource entity) { if (entity.getForcedId() != null) { if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY) { if (theId.isIdPartValidLong()) { // This means that the resource with the given numeric ID exists, but it has a "forced ID", meaning that // as far as the outside world is concerned, the given ID doesn't exist (it's just an internal pointer // to the // forced ID) throw new ResourceNotFoundException(theId); } } } }
public static void validateResourceType(BaseHasResource theEntity, String theResourceName) { if (!theResourceName.equals(theEntity.getResourceType())) { throw new ResourceNotFoundException( "Resource with ID " + theEntity.getIdDt().getIdPart() + " exists but it is not of type " + theResourceName + ", found resource of type " + theEntity.getResourceType()); } } }
@Override @Transactional(propagation = Propagation.NEVER) public ExpungeOutcome expunge(IIdType theId, ExpungeOptions theExpungeOptions) { TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager); BaseHasResource entity = txTemplate.execute(t->readEntity(theId)); if (theId.hasVersionIdPart()) { BaseHasResource currentVersion; currentVersion = txTemplate.execute(t->readEntity(theId.toVersionless())); if (entity.getVersion() == currentVersion.getVersion()) { throw new PreconditionFailedException("Can not perform version-specific expunge of resource " + theId.toUnqualified().getValue() + " as this is the current version"); } return doExpunge(getResourceName(), entity.getResourceId(), entity.getVersion(), theExpungeOptions); } return doExpunge(getResourceName(), entity.getResourceId(), null, theExpungeOptions); }
@Override public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequestDetails) { // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); } Set<TagDefinition> tagDefs = new HashSet<>(); BaseHasResource entity = readEntity(theId); for (BaseTag next : entity.getTags()) { tagDefs.add(next.getTag()); } MT retVal = toMetaDt(theType, tagDefs); retVal.setLastUpdated(entity.getUpdatedDate()); retVal.setVersionId(Long.toString(entity.getVersion())); return retVal; }
private <MT extends IBaseMetaType> void doMetaDelete(MT theMetaDel, BaseHasResource entity) { List<TagDefinition> tags = toTagList(theMetaDel); //@formatter:off for (TagDefinition nextDef : tags) { for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) { if (ObjectUtil.equals(next.getTag().getTagType(), nextDef.getTagType()) && ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) && ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) { myEntityManager.remove(next); entity.getTags().remove(next); } } } //@formatter:on if (entity.getTags().isEmpty()) { entity.setHasTags(false); } myEntityManager.merge(entity); }
@Override public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) { // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId); notifyInterceptors(RestOperationTypeEnum.META_DELETE, requestDetails); } StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theResourceId); if (entity == null) { throw new ResourceNotFoundException(theResourceId); } ResourceTable latestVersion = readEntityLatestVersion(theResourceId); if (latestVersion.getVersion() != entity.getVersion()) { doMetaDelete(theMetaDel, entity); } else { doMetaDelete(theMetaDel, latestVersion); // Also update history entry ResourceHistoryTable history = myResourceHistoryTableDao.findForIdAndVersion(entity.getId(), entity.getVersion()); doMetaDelete(theMetaDel, history); } myEntityManager.flush(); ourLog.debug("Processed metaDeleteOperation on {} in {}ms", new Object[] {theResourceId.getValue(), w.getMillisAndRestart()}); @SuppressWarnings("unchecked") MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId, theRequestDetails); return retVal; }
@Override public IBundleProvider history(final IIdType theId, final Date theSince, Date theUntil, RequestDetails theRequestDetails) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); notifyInterceptors(RestOperationTypeEnum.HISTORY_INSTANCE, requestDetails); StopWatch w = new StopWatch(); IIdType id = theId.withResourceType(myResourceName).toUnqualifiedVersionless(); BaseHasResource entity = readEntity(id); IBundleProvider retVal = super.history(myResourceName, entity.getId(), theSince, theUntil); ourLog.debug("Processed history on {} in {}ms", id, w.getMillisAndRestart()); return retVal; }
@Override public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType()); Class<? extends IBaseResource> resourceType = type.getImplementingClass(); return toResource(resourceType, theEntity, null, theForHistoryOperation); }
@Override public T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk) { validateResourceTypeAndThrowIllegalArgumentException(theId); // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); RestOperationTypeEnum operationType = theId.hasVersionIdPart() ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ; notifyInterceptors(operationType, requestDetails); } StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theId); validateResourceType(entity); T retVal = toResource(myResourceType, entity, null, false); if (theDeletedOk == false) { if (entity.getDeleted() != null) { throw new ResourceGoneException("Resource was deleted at " + new InstantType(entity.getDeleted()).getValueAsString()); } } ourLog.debug("Processed read on {} in {}ms", theId.getValue(), w.getMillisAndRestart()); return retVal; }
BaseHasResource entity = dao.readEntity(theResourceId); TagList retVal = new TagList(); for (BaseTag next : entity.getTags()) { retVal.add(next.getTag().toTag());
throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidVersion", theId.getVersionIdPart(), theId.toUnqualifiedVersionless())); if (entity.getVersion() != theId.getVersionIdPartAsLong()) { entity = null;
@Override public <MT extends IBaseMetaType> MT metaGetOperation(Class<MT> theType, IIdType theId, RequestDetails theRequestDetails) { // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); notifyInterceptors(RestOperationTypeEnum.META, requestDetails); } Set<TagDefinition> tagDefs = new HashSet<>(); BaseHasResource entity = readEntity(theId); for (BaseTag next : entity.getTags()) { tagDefs.add(next.getTag()); } MT retVal = toMetaDt(theType, tagDefs); retVal.setLastUpdated(entity.getUpdatedDate()); retVal.setVersionId(Long.toString(entity.getVersion())); return retVal; }
@Override public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, RequestDetails theRequestDetails) { // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails); } StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theId); if (entity == null) { throw new ResourceNotFoundException(theId); } for (BaseTag next : new ArrayList<>(entity.getTags())) { if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) && ObjectUtil.equals(next.getTag().getSystem(), theScheme) && ObjectUtil.equals(next.getTag().getCode(), theTerm)) { myEntityManager.remove(next); entity.getTags().remove(next); } } if (entity.getTags().isEmpty()) { entity.setHasTags(false); } myEntityManager.merge(entity); ourLog.debug("Processed remove tag {}/{} on {} in {}ms", theScheme, theTerm, theId.getValue(), w.getMillisAndRestart()); }
@Override public <MT extends IBaseMetaType> MT metaAddOperation(IIdType theResourceId, MT theMetaAdd, RequestDetails theRequestDetails) { // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId); notifyInterceptors(RestOperationTypeEnum.META_ADD, requestDetails); } StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theResourceId); if (entity == null) { throw new ResourceNotFoundException(theResourceId); } ResourceTable latestVersion = readEntityLatestVersion(theResourceId); if (latestVersion.getVersion() != entity.getVersion()) { doMetaAdd(theMetaAdd, entity); } else { doMetaAdd(theMetaAdd, latestVersion); // Also update history entry ResourceHistoryTable history = myResourceHistoryTableDao.findForIdAndVersion(entity.getId(), entity.getVersion()); doMetaAdd(theMetaAdd, history); } ourLog.debug("Processed metaAddOperation on {} in {}ms", new Object[] {theResourceId, w.getMillisAndRestart()}); @SuppressWarnings("unchecked") MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId, theRequestDetails); return retVal; }
public static void validateResourceType(BaseHasResource theEntity, String theResourceName) { if (!theResourceName.equals(theEntity.getResourceType())) { throw new ResourceNotFoundException( "Resource with ID " + theEntity.getIdDt().getIdPart() + " exists but it is not of type " + theResourceName + ", found resource of type " + theEntity.getResourceType()); } } }
@Override @Transactional(propagation = Propagation.NEVER) public ExpungeOutcome expunge(IIdType theId, ExpungeOptions theExpungeOptions) { TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager); BaseHasResource entity = txTemplate.execute(t->readEntity(theId)); if (theId.hasVersionIdPart()) { BaseHasResource currentVersion; currentVersion = txTemplate.execute(t->readEntity(theId.toVersionless())); if (entity.getVersion() == currentVersion.getVersion()) { throw new PreconditionFailedException("Can not perform version-specific expunge of resource " + theId.toUnqualified().getValue() + " as this is the current version"); } return doExpunge(getResourceName(), entity.getResourceId(), entity.getVersion(), theExpungeOptions); } return doExpunge(getResourceName(), entity.getResourceId(), null, theExpungeOptions); }
@Override public IBundleProvider history(final IIdType theId, final Date theSince, Date theUntil, RequestDetails theRequestDetails) { // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); notifyInterceptors(RestOperationTypeEnum.HISTORY_INSTANCE, requestDetails); StopWatch w = new StopWatch(); IIdType id = theId.withResourceType(myResourceName).toUnqualifiedVersionless(); BaseHasResource entity = readEntity(id); IBundleProvider retVal = super.history(myResourceName, entity.getId(), theSince, theUntil); ourLog.debug("Processed history on {} in {}ms", id, w.getMillisAndRestart()); return retVal; }
@Override public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType()); Class<? extends IBaseResource> resourceType = type.getImplementingClass(); return toResource(resourceType, theEntity, null, theForHistoryOperation); }