X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fsparky%2Feditattributes%2FAttributeUpdater.java;h=f992da7f45ff69fd37ba5407ae8573c32231b677;hb=9eb9e258f0ab06a516f6d88d1aedc36fc22aeeaf;hp=5e6d6522fd7b31ee97310be5a4562deb456d007b;hpb=05e74c6879ab564181e7cf92e4444d17cc7e25d4;p=aai%2Fsparky-be.git diff --git a/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java b/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java index 5e6d652..f992da7 100644 --- a/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java +++ b/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java @@ -38,7 +38,6 @@ import org.onap.aai.restclient.client.OperationResult; import org.onap.aai.sparky.config.oxm.OxmEntityLookup; import org.onap.aai.sparky.config.oxm.OxmModelLoader; import org.onap.aai.sparky.dal.ActiveInventoryAdapter; -import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig; import org.onap.aai.sparky.editattributes.exception.AttributeUpdateException; import org.onap.aai.sparky.logging.AaiUiMsgs; @@ -53,7 +52,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; * */ public class AttributeUpdater { - + /** * The Class AaiEditObject. */ @@ -131,34 +130,30 @@ public class AttributeUpdater { private static final String MESSAGE_VERSION_EXTRACTION_REGEX = "\\/(v[0-9]+)"; private static final String ATTRIBUTES_UPDATED_SUCCESSFULLY = "Attributes updated successfully"; private static final String ATTRIBUTES_NOT_UPDATED = "Attributes not updated. "; - private ActiveInventoryConfig aaiConfig; + private ActiveInventoryAdapter aaiAdapter; private UserValidator validator; private OxmModelLoader oxmModelLoader; private OxmEntityLookup oxmEntityLookup; - + /** * Instantiates a new attribute updater. - * - * @throws AttributeUpdateException + * @throws AttributeUpdateException */ - public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, - ActiveInventoryAdapter activeInventoryAdapter) throws AttributeUpdateException { + public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, ActiveInventoryAdapter activeInventoryAdapter) throws AttributeUpdateException { super(); this.oxmModelLoader = oxmModelLoader; this.oxmEntityLookup = oxmEntityLookup; this.aaiAdapter = activeInventoryAdapter; - + try { - this.aaiConfig = ActiveInventoryConfig.getConfig(); // TODO -> Config to become a bean this.validator = new UserValidator(); } catch (Exception exc) { - LOG.error(AaiUiMsgs.ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER, - exc.getLocalizedMessage()); + LOG.error(AaiUiMsgs.ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER, exc.getLocalizedMessage()); throw new AttributeUpdateException(exc); } } - + protected String getResourceBasePath() { String versionStr = null; @@ -169,26 +164,26 @@ public class AttributeUpdater { return "/aai/v" + versionStr; } - + protected URI getBaseUri() { - return UriBuilder.fromUri("https://" + aaiConfig.getAaiRestConfig().getHost() + ":" - + aaiConfig.getAaiRestConfig().getPort() + getResourceBasePath()).build(); + return UriBuilder + .fromUri("https://" + aaiAdapter.getEndpointConfig().getEndpointIpAddress() + ":" + + aaiAdapter.getEndpointConfig().getEndpointServerPort() + getResourceBasePath()) + .build(); } /** * Update object attribute. * * @param objectUri - Valid URI of the object as per OXM model. - * @param attributeValues - Map of (attribute-name & attribute-value) for any attributes to be - * updated to the value. + * @param attributeValues - Map of (attribute-name & attribute-value) for + * any attributes to be updated to the value. * @param attUid - ATTUID of the user requesting the update. * @return - OperationResult with success or failure reason. */ - public OperationResult updateObjectAttribute(String objectUri, - Map attributeValues, String attUid) { + public OperationResult updateObjectAttribute(String objectUri, Map attributeValues, String attUid) { OperationResult result = new OperationResult(); - LOG.info(AaiUiMsgs.ATTRIBUTES_UPDATE_METHOD_CALLED, objectUri, attUid, - String.valueOf(attributeValues)); + LOG.info(AaiUiMsgs.ATTRIBUTES_UPDATE_METHOD_CALLED, objectUri, attUid, String.valueOf(attributeValues)); if (!validator.isAuthorizedUser(attUid)) { result.setResultCode(403); result.setResult(String.format("User %s is not authorized for Attributes update ", attUid)); @@ -210,24 +205,23 @@ public class AttributeUpdater { String jsonPayload = convertEditRequestToJson(object, attributeValues); String patchUri = getBaseUri().toString() + getRelativeUri(objectUri); - + /* - * FIX ME: Dave Adams, 8-Nov-2017 + * FIX ME: Dave Adams, 8-Nov-2017 */ - - // result = aaiAdapter.doPatch(patchUri, jsonPayload, MediaType.APPLICATION_JSON); + + //result = aaiAdapter.doPatch(patchUri, jsonPayload, MediaType.APPLICATION_JSON); result = new OperationResult(); result.setResultCode(404); - + if (result.getResultCode() == 200) { result.setResult(ATTRIBUTES_UPDATED_SUCCESSFULLY); String message = result.getResult() + " for " + objectUri; LOG.info(AaiUiMsgs.INFO_GENERIC, message); } else { - String message = - ATTRIBUTES_NOT_UPDATED + " For: " + objectUri + ". AAI PATCH Status Code : " - + result.getResultCode() + ". Error : " + result.getResult(); + String message = ATTRIBUTES_NOT_UPDATED + " For: " + objectUri + ". AAI PATCH Status Code : " + + result.getResultCode() + ". Error : " + result.getResult(); LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_MESSAGE, message); } } catch (AttributeUpdateException exc) { @@ -270,7 +264,7 @@ public class AttributeUpdater { AaiEditObject object = new AaiEditObject(); String version = getVersionFromUri(objectUri); - if (null == version) { + if ( null == version ) { version = "v" + String.valueOf(oxmModelLoader.getLatestVersionNum()); } object.setSchemaVersion(version); @@ -288,14 +282,14 @@ public class AttributeUpdater { String objectJavaType = null; Map entityTypeLookup = oxmEntityLookup.getEntityTypeLookup(); DynamicType entity = entityTypeLookup.get(rootElement); - if (null != entity) { + if ( null != entity ) { objectJavaType = entity.getName(); - String message = - "Descriptor: Alias: " + objectJavaType + " : DefaultRootElement: " + rootElement; + String message = "Descriptor: Alias: " + objectJavaType + " : DefaultRootElement: " + + rootElement; LOG.debug(AaiUiMsgs.DEBUG_GENERIC, message); } - - + + if (objectJavaType == null) { throw new AttributeUpdateException( "Object type could not be determined from the URI : " + objectUri);