/** * Creates an instance. * * @param fudgeContext the Fudge context, not null * @param baseTarget the RESTful target, not null * @param changeManager the change manager, not null */ public RemoteSecurityMaster( FudgeContext fudgeContext, RestTarget baseTarget, ChangeManager changeManager) { ArgumentChecker.notNull(changeManager, "changeManager"); _fudgeContext = fudgeContext; _targetSecurity = baseTarget.resolveBase(SECURITYMASTER_SECURITY); _targetMetaData = baseTarget.resolve(SECURITYMASTER_METADATA); _targetSearch = baseTarget.resolve(SECURITYMASTER_SEARCH); _targetHistoric = baseTarget.resolve(SECURITYMASTER_HISTORIC); _restClient = RestClient.getInstance(fudgeContext, null); _changeManager = changeManager; }
@Override public SecurityDocument get(ObjectIdentifiable objectId, VersionCorrection versionCorrection) { final RestTarget target = _targetSecurity.resolve(objectId.getObjectId().toString()); if (versionCorrection != null && versionCorrection.getVersionAsOf() != null) { target.resolveQuery( "versionAsOf", Collections.singletonList(versionCorrection.getVersionAsOf().toString())); } if (versionCorrection != null && versionCorrection.getCorrectedTo() != null) { target.resolveQuery( "correctedTo", Collections.singletonList(versionCorrection.getCorrectedTo().toString())); } s_logger.debug("get-get to {}", target); final FudgeMsg message = getRestClient().getMsg(target); if (message == null) { s_logger.debug("get-recv NULL"); throw new DataNotFoundException("Security with identifier " + objectId); } s_logger.debug("get-recv {}", message); return getFudgeDeserializer().fudgeMsgToObject(SecurityDocument.class, message); }
@Override public SecurityDocument get(UniqueId uid) { final RestTarget target = _targetSecurity.resolve(uid.toString()); s_logger.debug("get-get to {}", target); final FudgeMsg message = getRestClient().getMsg(target); if (message == null) { s_logger.debug("get-recv NULL"); throw new DataNotFoundException("Security with identifier " + uid); } s_logger.debug("get-recv {}", message); return getFudgeDeserializer().fudgeMsgToObject(SecurityDocument.class, message); }
@Override public SecurityDocument correct(SecurityDocument document) { final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document); final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString()); s_logger.debug("correct-put {} to {}", payload, target); final FudgeMsgEnvelope env = getRestClient().put(target, payload); if (env == null) { s_logger.debug("correct-recv NULL"); return null; } s_logger.debug("correct-recv {}", env.getMessage()); return document; }
@Override public SecurityDocument update(SecurityDocument document) { final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document); final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString()); s_logger.debug("update-post {} to {}", payload, target); final FudgeMsgEnvelope env = getRestClient().post(target, payload); if (env == null) { s_logger.debug("update-recv NULL"); return null; } s_logger.debug("update-recv {}", env.getMessage()); document.setUniqueId(getFudgeDeserializer().fudgeMsgToObject(UniqueId.class, env.getMessage())); return document; }
@Override public void remove(UniqueId uid) { final RestTarget target = _targetSecurity.resolve(uid.toString()); s_logger.debug("remove-post to {}", target); getRestClient().delete(target); }