ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, idToDelete.getResourceType(), idToDelete); notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, idToDelete.getResourceType(), idToDelete);
public void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails theRequestDetails) { if (theRequestDetails.getId() != null && theRequestDetails.getId().hasResourceType() && isNotBlank(theRequestDetails.getResourceType())) { if (theRequestDetails.getId().getResourceType().equals(theRequestDetails.getResourceType()) == false) { throw new InternalErrorException( "Inconsistent server state - Resource types don't match: " + theRequestDetails.getId().getResourceType() + " / " + theRequestDetails.getResourceType()); } } if (theRequestDetails.getUserData().get(PROCESSING_SUB_REQUEST) == Boolean.TRUE) { theRequestDetails.notifyIncomingRequestPreHandled(theOperationType); } List<IServerInterceptor> interceptors = getConfig().getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, theRequestDetails); } }
@Override protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); theDetails.setResource((IBaseResource) theRequestDetails.getUserData().get(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY)); }
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, getContext(), theResource); notifyInterceptors(RestOperationTypeEnum.CREATE, requestDetails);
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, idToDelete.getResourceType(), idToDelete); notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, idToDelete.getResourceType(), idToDelete);
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, getContext(), theId.getResourceType(), theId); notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, getContext(), theId.getResourceType(), theId); theRequest.getRequestOperationCallback().resourceDeleted(resourceToDelete);
requestDetails = new ActionRequestDetails(theRequestDetails, theResource, theResourceId.getResourceType(), theResourceId); notifyInterceptors(RestOperationTypeEnum.UPDATE, requestDetails);
@Override public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, theResource, null, theId); notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails);
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), getResourceName(), null); notifyInterceptors(RestOperationTypeEnum.SEARCH_TYPE, requestDetails);
@Override public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, theResource, null, theId); notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails);
@Override public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, theResource, null, theId); notifyInterceptors(RestOperationTypeEnum.VALIDATE, requestDetails);
@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 <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; }
protected final Object invokeServerMethod(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) { // Handle server action interceptors RestOperationTypeEnum operationType = getRestOperationType(theRequest); if (operationType != null) { for (IServerInterceptor next : theServer.getInterceptors()) { ActionRequestDetails details = new ActionRequestDetails(theRequest); populateActionRequestDetailsForInterceptor(theRequest, details, theMethodParams); next.incomingRequestPreHandled(operationType, details); } } // Actually invoke the method try { Method method = getMethod(); return method.invoke(getProvider(), theMethodParams); } catch (InvocationTargetException e) { if (e.getCause() instanceof BaseServerResponseException) { throw (BaseServerResponseException) e.getCause(); } throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } catch (Exception e) { throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } }
@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 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; }
@Override public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) { boolean isEnabled = Boolean.valueOf(enabled); if (isEnabled && baselineDate != null) { // transform dates switch (theOperation) { case CREATE: case DELETE: case UPDATE: IBaseResource resource = theProcessedRequest.getResource(); // todo need to do something here break; default: break; } super.incomingRequestPreHandled(theOperation, theProcessedRequest); } else { super.incomingRequestPreHandled(theOperation, theProcessedRequest); } } }
/** * This method may be invoked by user code to notify interceptors that a nested * operation is being invoked which is denoted by this request details. */ public void notifyIncomingRequestPreHandled(RestOperationTypeEnum theOperationType) { RequestDetails requestDetails = getRequestDetails(); if (requestDetails == null) { return; } IRestfulServerDefaults server = requestDetails.getServer(); if (server == null) { return; } List<IServerInterceptor> interceptors = server.getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, this); } }
@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 incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) { IBaseResource inputResource = null; IIdType inputResourceId = null; switch (determineOperationDirection(theOperation, theProcessedRequest.getResource())) { case IN: case BOTH: inputResource = theProcessedRequest.getResource(); inputResourceId = theProcessedRequest.getId(); break; case OUT: // inputResource = null; inputResourceId = theProcessedRequest.getId(); break; case NONE: return; } RequestDetails requestDetails = theProcessedRequest.getRequestDetails(); applyRulesAndFailIfDeny(theOperation, requestDetails, inputResource, inputResourceId, null); }