diff options
author | sstoykov <stela.stoykova@amdocs.com> | 2018-11-26 15:45:47 -0500 |
---|---|---|
committer | sstoykov <stela.stoykova@amdocs.com> | 2018-11-27 15:24:24 -0500 |
commit | 5e4b48acc875f88e2958b4469cb889222ca2f11c (patch) | |
tree | e432b2932ebc442cd8c50b0b76e41cb01f307405 | |
parent | 14f155e7a8a93b499b4f4eed801281dc92faca14 (diff) |
Removed edit attribute code
Removed obsolete code related to the edit attributes feature from
sparky-be.
Issue-ID: AAI-1956
Change-Id: I25754ec5440ce199ca5678b2074a1f090dde46ab
Signed-off-by: sstoykov <stela.stoykova@amdocs.com>
19 files changed, 4 insertions, 1517 deletions
diff --git a/sparkybe-onap-application/config/spring-beans/sparky-attribute-update-service.xml b/sparkybe-onap-application/config/spring-beans/sparky-attribute-update-service.xml deleted file mode 100644 index 27db51a..0000000 --- a/sparkybe-onap-application/config/spring-beans/sparky-attribute-update-service.xml +++ /dev/null @@ -1,20 +0,0 @@ -<beans profile="resources" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" - xmlns:task="http://www.springframework.org/schema/task" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd - http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"> - - <bean id="attributeUpdater" class="org.onap.aai.sparky.editattributes.AttributeUpdater"> - <constructor-arg ref="oxmModelLoader" /> - <constructor-arg ref="oxmEntityLookup" /> - <constructor-arg ref="activeInventoryAdapter" /> - <constructor-arg name="domain" value="${resources.domain:aai}" /> - </bean> - - <bean id="attributeEditProcessor" - class="org.onap.aai.sparky.editattributes.AttributeEditProcessor"> - <constructor-arg ref="attributeUpdater" /> - </bean> - -</beans>
\ No newline at end of file diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java deleted file mode 100644 index fbdbb94..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeEditProcessor.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes; - -import java.io.UnsupportedEncodingException; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.component.restlet.RestletConstants; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.onap.aai.cl.mdc.MdcContext; -import org.onap.aai.restclient.client.OperationResult; -import org.onap.aai.sparky.editattributes.entity.EditRequest; -import org.onap.aai.sparky.logging.AaiUiMsgs; -import org.onap.aai.sparky.util.NodeUtils; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.data.ClientInfo; -import org.restlet.data.Cookie; -import org.restlet.data.MediaType; -import org.restlet.data.Status; -import org.restlet.util.Series; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * The Class AttributeEditProcessor. - */ -public class AttributeEditProcessor { - - private static final Logger LOG = - LoggerFactory.getInstance().getLogger(AttributeEditProcessor.class); - - private ObjectMapper mapper; - private AttributeUpdater attrUpdater; - - public AttributeEditProcessor(AttributeUpdater attributeUpdater) { - this.attrUpdater = attributeUpdater; - - this.mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_EMPTY); - } - - public void editAttribute(Exchange exchange) { - - Object xTransactionId = exchange.getIn().getHeader("X-TransactionId"); - - if (xTransactionId == null) { - xTransactionId = NodeUtils.getRandomTxnId(); - } - - Object partnerName = exchange.getIn().getHeader("X-FromAppId"); - if (partnerName == null) { - partnerName = "Browser"; - } - - Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class); - - /* - * Disables automatic Apache Camel Restlet component logging which prints out an undesirable log - * entry which includes client (e.g. browser) information - */ - request.setLoggable(false); - - ClientInfo clientInfo = request.getClientInfo(); - MdcContext.initialize((String) xTransactionId, "AAI-UI", "", (String) partnerName, - clientInfo.getAddress() + ":" + clientInfo.getPort()); - - String payload = exchange.getIn().getBody(String.class); - EditRequest editRequest = null; - OperationResult operationResult = new OperationResult(); - - Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class); - response.setStatus(Status.SUCCESS_OK); // 200 is assumed unless an actual exception occurs (a failure is still a valid response) - - boolean wasErrorDuringProcessing = false; - String errorMessage = null; - - - try { - - if (payload != null && !payload.isEmpty()) { - editRequest = mapper.readValue(payload, EditRequest.class); - - if (editRequest != null) { - - String attUid = getAttUid(request.getCookies()); - String objectUri = editRequest.getEntityUri(); - Map<String, Object> attributeValues = editRequest.getAttributes(); - - if (attUid != null && !attUid.isEmpty() && objectUri != null && !objectUri.isEmpty() - && attributeValues != null && !attributeValues.isEmpty()) { - - LOG.info(AaiUiMsgs.ATTRIBUTES_HANDLING_EDIT, objectUri, editRequest.toString()); - - operationResult = attrUpdater.updateObjectAttribute(objectUri, attributeValues, attUid); - - boolean wasSuccess = (operationResult.getResultCode() == 200); - String message = String.format("Edit Attributes completed with Result Code : %s (%s).", - operationResult.getResultCode(), wasSuccess ? "success" : "failed"); - - LOG.info(AaiUiMsgs.INFO_GENERIC, message); - } - } - } else { - wasErrorDuringProcessing = true; - errorMessage = "Empty payload provided, need details to complete request"; - } - } catch (Exception exc) { - LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_EXCEPTION, exc.getLocalizedMessage()); - operationResult.setResult(500, "Error encountered while trying to update attributes."); - response.setStatus(Status.SERVER_ERROR_INTERNAL); - } - - if(wasErrorDuringProcessing) { - LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_MESSAGE, errorMessage); - } - - response.setEntity(operationResult.getResult(), MediaType.APPLICATION_JSON); - exchange.getOut().setBody(response); - } - - /** - * Gets the att uid. - * - * @param request the request - * @return the att uid - * @throws UnsupportedEncodingException the unsupported encoding exception - */ - public String getAttUid(Series<Cookie> cookies) throws UnsupportedEncodingException { - String attId = ""; - if (cookies == null) { - LOG.error(AaiUiMsgs.COOKIE_NOT_FOUND); - return attId; - } - for (Cookie cookie : cookies) { - if (cookie.getName().equals("attESHr")) { - // This cookie is of the form : - // "FIRSTNAME|LASTNAME|emailname@domain.com|||ab1234||fl6789,RBFMSKQ," - // + "Z9V2298,9762186|YNNNNNNNNNNNNNYNNYYNNNNN|FIRSTNAME|EY6SC9000|" - // we are to extract fl6789 from this which would be the attuid for the user. - String value = cookie.getValue(); - value = java.net.URLDecoder.decode(value, "UTF-8"); - LOG.info(AaiUiMsgs.COOKIE_FOUND, value); - String[] values = value.split("\\|"); - if (values.length > 7) { - attId = (values[7].split(","))[0]; - - String initials = (values[0].substring(0, 1) + values[1].substring(0, 1)).toLowerCase(); - if (attId.startsWith(initials)) { - return attId; - } - } - } - } - return attId; - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java deleted file mode 100644 index 23928a5..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java +++ /dev/null @@ -1,360 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes; - -import java.net.URI; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.ws.rs.core.UriBuilder; - -import org.eclipse.persistence.dynamic.DynamicType; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -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.editattributes.exception.AttributeUpdateException; -import org.onap.aai.sparky.logging.AaiUiMsgs; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.PropertyNamingStrategy; - -/** - * Class to process attribute updates on AAI objects. - * - * - */ -public class AttributeUpdater { - - /** - * The Class AaiEditObject. - */ - public class AaiEditObject { - String objectType; - String rootElement; - String keyName; - String keyValue; - String schemaVersion; - - /** - * Instantiates a new aai edit object. - */ - public AaiEditObject() { - - } - - /** - * Instantiates a new aai edit object. - * - * @param objectType the object type - * @param idName the id name - * @param schemaVersion the schema version - */ - public AaiEditObject(String objectType, String idName, String schemaVersion) { - super(); - this.objectType = objectType; - this.keyName = idName; - this.schemaVersion = schemaVersion; - } - - public String getObjectType() { - return objectType; - } - - public void setObjectType(String objectType) { - this.objectType = objectType; - } - - public String getKeyName() { - return keyName; - } - - public void setKeyName(String idName) { - this.keyName = idName; - } - - public String getSchemaVersion() { - return schemaVersion; - } - - public void setSchemaVersion(String schemaVersion) { - this.schemaVersion = schemaVersion; - } - - public void setKeyValue(String keyValue) { - this.keyValue = keyValue; - } - - public String getKeyValue() { - return keyValue; - } - - public String getRootElement() { - return rootElement; - } - - public void setRootElement(String rootElement) { - this.rootElement = rootElement; - } - - } - - private static final Logger LOG = LoggerFactory.getInstance().getLogger(AttributeUpdater.class); - 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 ActiveInventoryAdapter aaiAdapter; - private UserValidator validator; - private OxmModelLoader oxmModelLoader; - private OxmEntityLookup oxmEntityLookup; - private String domain; - - /** - * Instantiates a new attribute updater. - * @throws AttributeUpdateException - */ - public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, ActiveInventoryAdapter activeInventoryAdapter,String domain) throws AttributeUpdateException { - super(); - this.oxmModelLoader = oxmModelLoader; - this.oxmEntityLookup = oxmEntityLookup; - this.aaiAdapter = activeInventoryAdapter; - this.domain = domain; - - try { - this.validator = new UserValidator(); - } catch (Exception exc) { - LOG.error(AaiUiMsgs.ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER, exc.getLocalizedMessage()); - throw new AttributeUpdateException(exc); - } - } - - protected String getResourceBasePath() { - - String versionStr = null; - if (oxmModelLoader != null) { - versionStr = String.valueOf(oxmModelLoader.getOxmApiVersion()); - } - - return "/" + domain + "/v" + versionStr; - - } - - protected URI getBaseUri() { - 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 attUid - ATTUID of the user requesting the update. - * @return - OperationResult with success or failure reason. - */ - public OperationResult updateObjectAttribute(String objectUri, Map<String, Object> attributeValues, String attUid) { - OperationResult result = new OperationResult(); - 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)); - LOG.error(AaiUiMsgs.ATTRIBUTES_USER_NOT_AUTHORIZED_TO_UPDATE, attUid); - return result; - } - - AaiEditObject object = null; - - try { - object = getEditObjectFromUri(objectUri); - } catch (AttributeUpdateException exc) { - result.setResultCode(400); - result.setResult(ATTRIBUTES_NOT_UPDATED); - LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_EXCEPTION, exc.getLocalizedMessage()); - return result; - } - try { - String jsonPayload = convertEditRequestToJson(object, attributeValues); - String patchUri = getBaseUri().toString() + getRelativeUri(objectUri); - - - /* - * FIX ME: Dave Adams, 8-Nov-2017 - */ - - //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(); - LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_MESSAGE, message); - } - } catch (AttributeUpdateException exc) { - result.setResultCode(500); - result.setResult(ATTRIBUTES_NOT_UPDATED + exc.getLocalizedMessage()); - LOG.error(AaiUiMsgs.ATTRIBUTES_NOT_UPDATED_EXCEPTION, exc.getLocalizedMessage()); - } - return result; - - } - - /** - * Gets the relative uri. - * - * @param objectUri the object uri - * @return the relative uri - */ - public String getRelativeUri(String objectUri) { - String tempUri = objectUri; - final Pattern pattern = Pattern.compile(MESSAGE_VERSION_EXTRACTION_REGEX, Pattern.DOTALL); - Matcher matcher = pattern.matcher(objectUri); - while (matcher.find()) { - tempUri = objectUri.substring(matcher.end()); - } - if (!tempUri.startsWith("/")) { - tempUri = "/" + tempUri; - } - return tempUri; - } - - /** - * Gets the edits the object from uri. - * - * @param objectUri the object uri - * @return the edits the object from uri - * @throws AttributeUpdateException the attribute update exception - */ - public AaiEditObject getEditObjectFromUri(String objectUri) throws AttributeUpdateException { - - AaiEditObject object = new AaiEditObject(); - String version = getVersionFromUri(objectUri); - - if ( null == version ) { - version = "v" + String.valueOf(oxmModelLoader.getOxmApiVersion()); - } - object.setSchemaVersion(version); - - String[] values = objectUri.split("/"); - if (values.length < 2) { - throw new AttributeUpdateException("Invalid or malformed object URI : " + objectUri); - } - String keyValue = values[values.length - 1]; - String rootElement = values[values.length - 2]; - - object.setKeyValue(keyValue); - object.setRootElement(rootElement); - - String objectJavaType = null; - Map<String, DynamicType> entityTypeLookup = oxmEntityLookup.getEntityTypeLookup(); - DynamicType entity = entityTypeLookup.get(rootElement); - if ( null != entity ) { - objectJavaType = entity.getName(); - 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); - } - object.setObjectType(objectJavaType); - - // Set key attribute name - final List<String> primaryKeys = entity.getDescriptor().getPrimaryKeyFieldNames(); - - if (primaryKeys.isEmpty()) { - throw new AttributeUpdateException("Object primary key not found in OXM version " + version); - } - - for (int i = 0; i < primaryKeys.size(); i++) { - final String primaryKey = primaryKeys.get(i); - if (primaryKey.indexOf("/text()") != -1) { - primaryKeys.set(i, primaryKey.replace("/text()", "")); - } - } - object.setKeyName(primaryKeys.iterator().next()); - - return object; - } - - /** - * Gets the version from uri. - * - * @param objectUri the object uri - * @return the version from uri - * @throws AttributeUpdateException the attribute update exception - */ - private String getVersionFromUri(String objectUri) throws AttributeUpdateException { - final Pattern pattern = Pattern.compile(MESSAGE_VERSION_EXTRACTION_REGEX, Pattern.DOTALL); - Matcher matcher = pattern.matcher(objectUri); - String messageSchemaVersion = null; - while (matcher.find()) { - messageSchemaVersion = matcher.group(1); - break; - } - return messageSchemaVersion; - } - - /** - * Convert edit request to json. - * - * @param object the object - * @param attributeValues the attribute values - * @return the string - * @throws AttributeUpdateException the attribute update exception - */ - private static String convertEditRequestToJson(AaiEditObject object, - Map<String, Object> attributeValues) throws AttributeUpdateException { - - ObjectMapper mapper = new ObjectMapper(); - mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.KebabCaseStrategy()); - ObjectWriter ow = mapper.writer(); - - Map<String, Object> patchAttributes = new HashMap<>(); - patchAttributes.put(object.getKeyName(), object.getKeyValue()); - patchAttributes.putAll(attributeValues); - - try { - return ow.writeValueAsString(patchAttributes); - } catch (JsonProcessingException exc) { - throw new AttributeUpdateException("Caught a JPE while creating PATCH request body = ", exc); - } - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserAuthorizationReader.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserAuthorizationReader.java deleted file mode 100644 index 170ed5f..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserAuthorizationReader.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Reads user IDs from a file. Each line in the user authorization file should contain a single user - * ID. For example, - * - * <pre> - * user1 - * user2 - * </pre> - */ -public class UserAuthorizationReader { - - private File userAuthorizationFile; - - /** - * Set the user authorization file. - * - * @param file a user authorization file - */ - public UserAuthorizationReader(File file) { - this.userAuthorizationFile = file; - } - - /** - * Gets user IDs from a file. - * - * @return a list of user IDs - * @throws IOException if there is a problem reading the user configuration file - */ - public List<String> getUsers() throws IOException { - List<String> userList = new ArrayList<>(); - try (Stream<String> stream = Files.lines(getUserAuthorizationFile().toPath())) { - userList.addAll(stream.map(String::trim).collect(Collectors.toList())); - } - return userList; - } - - // Getters and setters - public File getUserAuthorizationFile() { - return userAuthorizationFile; - } - - public void setUserAuthorizationFile(File file) { - this.userAuthorizationFile = file; - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java deleted file mode 100644 index 83b3932..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/UserValidator.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.onap.aai.sparky.logging.AaiUiMsgs; -import org.onap.aai.sparky.viewandinspect.config.SparkyConstants; - -/** - * Validates users against a user authorization file. - */ -public class UserValidator { - - private static final Logger LOG = LoggerFactory.getInstance().getLogger(UserValidator.class); - private static final String USER_AUTH_FILE = - SparkyConstants.AUTHORIZED_USERS_FILE_LOCATION; - - private UserAuthorizationReader userAuthorizationReader = - new UserAuthorizationReader(new File(USER_AUTH_FILE)); - - /** - * Returns true if the user is authorized. - * - * @param userId a user identifier - * @return true if the user ID is present in the user authorization file - */ - public boolean isAuthorizedUser(String userId) { - if (userId != null && !userId.isEmpty()) { - try { - List<String> users = userAuthorizationReader.getUsers(); - return users.contains(userId); - } catch (IOException exc) { - LOG.error(AaiUiMsgs.USER_AUTHORIZATION_FILE_UNAVAILABLE, userId); - return false; - } - } else { - return false; - } - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/entity/EditRequest.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/entity/EditRequest.java deleted file mode 100644 index eb34eab..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/entity/EditRequest.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes.entity; - -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * The Class EditRequest. - */ -public class EditRequest { - - @JsonProperty("entity-uri") - private String entityUri; - - @JsonProperty("entity-type") - private String entityType; - - @JsonProperty("attributes") - private Map<String, Object> attributes = new HashMap<>(); - - public String getEntityUri() { - return entityUri; - } - - public void setEntityUri(String entityUri) { - this.entityUri = entityUri; - } - - public String getEntityType() { - return entityType; - } - - public void setEntityType(String entityType) { - this.entityType = entityType; - } - - public Map<String, Object> getAttributes() { - return attributes; - } - - public void setAttributes(Map<String, Object> attributes) { - this.attributes = attributes; - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/exception/AttributeUpdateException.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/exception/AttributeUpdateException.java deleted file mode 100644 index 8ce56bd..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/exception/AttributeUpdateException.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.editattributes.exception; - -/** - * The Class AttributeUpdateException. - */ -public class AttributeUpdateException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Attribute Edit specific Exception Class. - * - * @param exc the exc - */ - - public AttributeUpdateException(Exception exc) { - super(exc); - } - - /** - * Instantiates a new attribute update exception. - * - * @param message the message - */ - public AttributeUpdateException(String message) { - super(message); - } - - /** - * Instantiates a new attribute update exception. - * - * @param message the message - * @param exc the exc - */ - public AttributeUpdateException(String message, Exception exc) { - super(message, exc); - } -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java index c86f5b1..90a1bd2 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/logging/AaiUiMsgs.java @@ -310,20 +310,6 @@ public enum AaiUiMsgs implements LogMessageEnum { AAI_RETRIEVAL_FAILED_GENERIC, /** Arguments: {0} = Self Link */ AAI_RETRIEVAL_FAILED_FOR_SELF_LINK, - /** Arguments: {0} = Exception */ - ATTRIBUTES_NOT_UPDATED_EXCEPTION, - /** Arguments: {0} = Message */ - ATTRIBUTES_NOT_UPDATED_MESSAGE, - /** Arguments: {0} = Exception */ - ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER, - /** Arguments: {0} = Schema File URI */ - ATTRIBUTES_ERROR_LOADING_MODEL_VERSION, - /** Arguments: {0} = Request URI {1} = Edit Request Body */ - ATTRIBUTES_HANDLING_EDIT, - /** Arguments: {0} = Object URI {1} = Attribute ID {2} Attribute Values */ - ATTRIBUTES_UPDATE_METHOD_CALLED, - /** Arguments: {0} = Attribute ID */ - ATTRIBUTES_USER_NOT_AUTHORIZED_TO_UPDATE, /** Arguments: {0} = Cookie */ COOKIE_FOUND, /** No argument */ diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java index c566e14..bcb7ba2 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/security/filter/LoginFilter.java @@ -123,17 +123,10 @@ public class LoginFilter implements Filter { // All other requests require ECOMP Portal authentication if (EcompSso.validateEcompSso(request) == null) { String redirectURL, logMessage; - if (request.getRequestURI().contains("/editAttributes")) { - // If request is for Edit Attributes UI, redirect straight to the application. - String appPath = request.getRequestURI().substring(request.getContextPath().length() + 1) - + (request.getQueryString() != null ? ("?" + request.getQueryString()) : ""); - redirectURL = SSOUtil.getECOMPSSORedirectURL(request, response, appPath); - logMessage = "Unauthenticated Edit Attributes UI login attempt."; - } else { - // Redirect to Portal UI - redirectURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL); - logMessage = "Unauthorized login attempt."; - } + + // Redirect to Portal UI + redirectURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL); + logMessage = "Unauthorized login attempt."; LOG.debug(AaiUiMsgs.LOGIN_FILTER_DEBUG, logMessage + diff --git a/sparkybe-onap-service/src/main/resources/logging/AAIUIMsgs.properties b/sparkybe-onap-service/src/main/resources/logging/AAIUIMsgs.properties index 94196e2..e9c61c9 100644 --- a/sparkybe-onap-service/src/main/resources/logging/AAIUIMsgs.properties +++ b/sparkybe-onap-service/src/main/resources/logging/AAIUIMsgs.properties @@ -122,14 +122,6 @@ DATA_CACHE_SUCCESS=\ AAIUI00025D|\ InMemoryEntityCache cached data with key = {0} -ATTRIBUTES_UPDATE_METHOD_CALLED=\ - AAIUI00026I|\ - updateObjectAttribute called for : {0} ATTUID : {1} Attributes : {2} - -ATTRIBUTES_HANDLING_EDIT=\ - AAIUI00027I|\ - Handling Edit Attributes: requestUri = {0} Body : {1} - RESTFULL_OP_COMPLETE=\ AAIUI00028I|\ doRestfulOperation() operation for {0} execution time = {1} ms for link = {2}, ResultCode = {3} @@ -329,14 +321,6 @@ EXECUTOR_SERV_EXCEPTION=\ AAIUI3003E|\ Thread: {0}. The following exception has occurred: {1} -ATTRIBUTES_NOT_UPDATED_EXCEPTION=\ - AAIUI3004E|\ - Attributes not updated. {0} - -ATTRIBUTES_NOT_UPDATED_MESSAGE=\ - AAIUI3005E|\ - {0} - SYNC_NOT_VALID_STATE_DURING_REQUEST=\ AAIUI3006E|\ Sync requested while synchronizer not in valid state. Current internal state: {0} @@ -493,10 +477,6 @@ PEGGING_ERROR=\ AAIUI30044E|\ Pegging UNKNOWN_EXCEPTION due to unexpected exception = {0} -ATTRIBUTES_ERROR_LOADING_MODEL_VERSION=\ - AAIUI30045E|\ - Model Version Error. {0} Not Found or not loaded successfully. - INVALID_REQUEST=\ AAIUI30046E|\ {0} @@ -589,10 +569,6 @@ RESTFULL_OP_ERROR_VERBOSE=\ AAIUI30069E|\ Error retrieving link: {0} from restful endpoint due to error: {1} -ATTRIBUTES_ERROR_GETTING_AAI_CONFIG_OR_ADAPTER=\ - AAIUI30070E|\ - Error in getting AAI configuration or Adaptor: {0} - USER_AUTHORIZATION_FILE_UNAVAILABLE=\ AAIUI30071E|\ User authorization file unavailable. User {0} cannot be authorized. @@ -609,10 +585,6 @@ FILE_NOT_FOUND=\ AAIUI30074E|\ Failed to find file: {0} -ATTRIBUTES_USER_NOT_AUTHORIZED_TO_UPDATE=\ - AAIUI30075E|\ - User {0} is not authorized for Attributes update - SELF_LINK_NULL_EMPTY_RESPONSE=\ AAIUI30076E|\ AIN - Failed to process null or empty pathed self link response diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java deleted file mode 100644 index a5f7049..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/AttributeUpdaterTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.Response.Status; - -import org.eclipse.persistence.dynamic.DynamicType; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.aai.restclient.client.OperationResult; -import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor; -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.editattributes.AttributeUpdater.AaiEditObject; - - - -/** - * The Class AttributeUpdaterTest. - */ -public class AttributeUpdaterTest { - - private ActiveInventoryAdapter aaiAdapter; - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @Before - public void setUp() throws Exception { - - aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); - } - - /** - * @throws Exception - */ - - @Test - public void testUpdateObjectAttribute() throws Exception { - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - AttributeUpdater updater = - new AttributeUpdater(new OxmModelLoader("v11", null, null), entityLookup, aaiAdapter,"aai"); - Map<String, Object> attributes = new HashMap<>(); - attributes.put("prov-status", "PREPROV"); - attributes.put("in-maint", "true"); - OperationResult result = updater.updateObjectAttribute( - "cloud-infrastructure/pservers/pserver/something", attributes, "someid"); - assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode()); - } - - - // This needs the OXM file in place to work. - /** - * Test get edit object from uri. - * - * @throws Exception the exception - */ - @Test(expected = NullPointerException.class) - public void testGetEditObjectFromUri() throws Exception { - String version = "v11"; - OxmModelLoader loader = new OxmModelLoader(version, null, null); - - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - - // DynamicType mockType = Mockito.mock(DynamicType.class); - // Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class); - - // Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity); - - - - HashMap<String, DynamicType> typeLookup = new HashMap<String, DynamicType>(); - // typeLookup.put("pserver", mockType); - - entityLookup.setEntityTypeLookup(typeLookup); - - - AttributeUpdater updater = - new AttributeUpdater(new OxmModelLoader(version, null, null), entityLookup, aaiAdapter,"aai"); - AaiEditObject result = updater.getEditObjectFromUri(null); - assertEquals("Pserver", result.getObjectType()); - assertEquals("pserver", result.getRootElement()); - assertEquals("hostname", result.getKeyName()); - assertEquals("mtznjtax101", result.getKeyValue()); - } - - /** - * Test get relative uri. - * - * @throws Exception the exception - */ - - @Test - public void testGetRelativeUri() throws Exception { - - OxmEntityDescriptor desc = new OxmEntityDescriptor(); - desc.addPrimaryKeyName("hostname"); - desc.setEntityName("pserver"); - - OxmEntityLookup entityLookup = new OxmEntityLookup(); - entityLookup.addEntityDescriptor("pserver", desc); - - AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader("v11",null,null), entityLookup, aaiAdapter,"aai"); - // Test entity uri without "/aai/version/" - String result = updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - result = updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - - result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101"); - assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); - } - -}
\ No newline at end of file diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java deleted file mode 100644 index 4e7e80a..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/EditAttributesTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import java.io.IOException; -import java.io.InputStream; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.BeforeClass; - - -/** - * The Class EditAttributesTest. - */ -public class EditAttributesTest { - String sampleJsonRequest = - "{ \"entity-uri\" : \"some/uri/value/here\", \"entity-type\" : \"complex\"," - + " \"attributes\" : { \"prov-status\" : \"PREPROV\", \"inMaint\" : \"true\"," - + " \"isClosedLoop\" : \"false\" }}"; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception {} - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @Before - public void setUp() throws Exception {} - - - /** - * Test analyze edit request body. - */ - /* - @Test - public void testAnalyzeEditRequestBody() { - AttributeEditProcessor aes = new AttributeEditProcessor(); - EditRequest request = aes.analyzeEditRequestBody(sampleJsonRequest); - System.out.println("JSON Body : " + sampleJsonRequest); - assertNotNull(request); - assertEquals("URI should match", "some/uri/value/here", request.getEntityUri()); - assertEquals("Entity Type should match", "complex", request.getEntityType()); - assertEquals("Attribute ProvStatus should match", "PREPROV", - request.getAttributes().get("prov-status")); - assertEquals("Attribute inMaint should be true", "true", - request.getAttributes().get("inMaint")); - assertEquals("Attribute isClosedLoop should be false", "false", - request.getAttributes().get("isClosedLoop")); - - } - */ - - - /** - * Test edit request. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ServletException the servlet exception - * @throws JSONException the JSON exception - */ - /* - @Test - public void testEditRequest() throws IOException, ServletException, JSONException { - HttpServletRequest mockRequest = mock(HttpServletRequest.class); - HttpServletResponse mockResponse = mock(HttpServletResponse.class); - ServletOutputStream mockOutput = mock(ServletOutputStream.class); - ServletInputStream mockInput = new MockServletInputStream(sampleJsonRequest); - - when(mockRequest.getRequestURI()).thenReturn("editAttributes"); - when(mockResponse.getOutputStream()).thenReturn(mockOutput); - - when(mockRequest.getInputStream()).thenReturn(mockInput); - - Principal princip = new UserPrincipal("ds1150"); - - when(mockRequest.getUserPrincipal()).thenReturn(princip); - - PrintWriter writer = new PrintWriter("editServletTest.txt"); - when(mockResponse.getWriter()).thenReturn(writer); - AttributeEditProcessor aes = new AttributeEditProcessor(); - aes.doPost(mockRequest, mockResponse); - JSONObject result = null; - try { - writer.close(); - result = new JSONObject(FileUtils.readFileToString(new File("editServletTest.txt"), "UTF-8")); - } catch (JSONException ex) { - // Nothing to catch - } - assertNotNull(result); - // assertEquals("Attributes updated successfully (just need PATCH !!!)", result.get("result")); - } - */ - - - - /** - * The Class MockServletInputStream. - */ - class MockServletInputStream extends ServletInputStream { - InputStream inputStream; - - /** - * Instantiates a new mock servlet input stream. - * - * @param string the string - */ - MockServletInputStream(String string) { - this.inputStream = IOUtils.toInputStream(string); - } - - /* (non-Javadoc) - * @see java.io.InputStream#read() - */ - @Override - public int read() throws IOException { - return inputStream.read(); - } - - @Override - public boolean isFinished() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isReady() { - // TODO Auto-generated method stub - return false; - } - - @Override - public void setReadListener(ReadListener readListener) { - // TODO Auto-generated method stub - - } - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java deleted file mode 100644 index 4f99b6d..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserAuthorizationReader.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.nio.file.Paths; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.aai.sparky.editattributes.UserAuthorizationReader; - -/** - * The Class TestUserAuthorizationReader. - */ -public class TestUserAuthorizationReader { - - private static File userAuthFile; - private static File userAuthFileEmpty; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - userAuthFile = Paths.get(TestData.USER_AUTH_FILE.getFilename()).toFile(); - userAuthFileEmpty = Paths.get(TestData.USER_AUTH_FILE_EMPTY.getFilename()).toFile(); - } - - /** - * The Enum TestData. - */ - enum TestData { - // @formatter:off - USER_AUTH_FILE( - "src/test/resources/user-auth-reader/authorized-users.config"), USER_AUTH_FILE_EMPTY( - "src/test/resources/user-auth-reader/authorized-users-empty.config"); - - private String filename; - - /** - * Instantiates a new test data. - * - * @param filename the filename - */ - TestData(String filename) { - this.filename = filename; - } - - public String getFilename() { - return this.filename; - } - // @formatter:on - } - - /** - * Test get users. - * - * @throws Exception the exception - */ - @Test - public void testGetUsers() throws Exception { - UserAuthorizationReader userAuthorizationReader = new UserAuthorizationReader(userAuthFile); - - // Method under test - List<String> userList = userAuthorizationReader.getUsers(); - - assertThat(userList, containsInAnyOrder("user1", "user2 user3", "user4")); - } - - /** - * Test get users passing empty config. - * - * @throws Exception the exception - */ - @Test - public void testGetUsersPassingEmptyConfig() throws Exception { - UserAuthorizationReader userConfigReader = new UserAuthorizationReader(userAuthFileEmpty); - - List<String> userList = userConfigReader.getUsers(); - - assertThat(userList, empty()); - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java deleted file mode 100644 index df41a5e..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/TestUserValidator.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.editattributes; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.nio.file.Paths; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.aai.sparky.editattributes.UserAuthorizationReader; -import org.onap.aai.sparky.editattributes.UserValidator; - -/** - * The Class TestUserValidator. - */ -@RunWith(MockitoJUnitRunner.class) -public class TestUserValidator { - - @Mock - private UserAuthorizationReader userAuthorizationReader; - - @InjectMocks - private UserValidator userValidator; - - private static File userAuthFile; - private static File missingUserAuthFile; - - /** - * Sets the up before class. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - userAuthFile = Paths.get(TestData.USER_AUTH_FILE.getFilename()).toFile(); - missingUserAuthFile = Paths.get(TestData.MISSING_USER_AUTH_FILE.getFilename()).toFile(); - } - - /** - * The Enum TestData. - */ - enum TestData { - // @formatter:off - USER_AUTH_FILE( - "src/test/resources/user-validator/authorized-users.config"), MISSING_USER_AUTH_FILE( - "src/test/resources/user-validator/missing.config"); - - private String filename; - - /** - * Instantiates a new test data. - * - * @param filename the filename - */ - TestData(String filename) { - this.filename = filename; - } - - public String getFilename() { - return this.filename; - } - // @formatter:on - } - - /** - * Test is authorized user. - * - * @throws Exception the exception - */ - @Test - public void testIsAuthorizedUser() throws Exception { - when(userAuthorizationReader.getUsers()).thenCallRealMethod(); - when(userAuthorizationReader.getUserAuthorizationFile()).thenReturn(userAuthFile); - - boolean isAuthUser = userValidator.isAuthorizedUser("user1"); - assertThat(isAuthUser, is(true)); - - boolean isAuthUser2 = userValidator.isAuthorizedUser("user2"); - assertThat(isAuthUser2, is(false)); - - boolean isAuthUser3 = userValidator.isAuthorizedUser("user3"); - assertThat(isAuthUser3, is(false)); - - boolean isAuthUser4 = userValidator.isAuthorizedUser("not-in-file"); - assertThat(isAuthUser4, is(false)); - - boolean isAuthUser5 = userValidator.isAuthorizedUser("user4"); - assertThat(isAuthUser5, is(true)); - } - - /** - * Test not authorized if file not present. - * - * @throws Exception the exception - */ - @Test - public void testNotAuthorizedIfFileNotPresent() throws Exception { - when(userAuthorizationReader.getUsers()).thenCallRealMethod(); - when(userAuthorizationReader.getUserAuthorizationFile()).thenReturn(missingUserAuthFile); - - boolean isAuthUser = userValidator.isAuthorizedUser("user1"); - assertThat(isAuthUser, is(false)); - } -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java deleted file mode 100644 index 5f87a27..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/editattributes/entity/EditRequestTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.onap.aai.sparky.editattributes.entity; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; - -import org.junit.Before; -import org.junit.Test; -import org.onap.aai.sparky.viewandinspect.EntityTypeAggregation; -import org.onap.aai.sparky.viewandinspect.entity.GraphMeta; - -import com.fasterxml.jackson.databind.node.JsonNodeFactory; - -public class EditRequestTest { - - private EditRequest editAttribute; - private HashMap<String,Object> attributes; - - - - @Before - public void init() throws Exception { - - editAttribute = new EditRequest(); - attributes = new HashMap<String,Object>(); - - } - - - @Test - public void updateValues() { - - editAttribute.setEntityUri(""); - assertNotNull(editAttribute.getEntityUri()); - editAttribute.setEntityType(""); - assertNotNull(editAttribute.getEntityType()); - editAttribute.setAttributes(attributes); - assertNotNull(editAttribute.getAttributes()); - } - -} diff --git a/sparkybe-onap-service/src/test/resources/oxm-reader/sparky-core.xml b/sparkybe-onap-service/src/test/resources/oxm-reader/sparky-core.xml index 86e4132..3a811ed 100644 --- a/sparkybe-onap-service/src/test/resources/oxm-reader/sparky-core.xml +++ b/sparkybe-onap-service/src/test/resources/oxm-reader/sparky-core.xml @@ -110,17 +110,6 @@ value="entitycounthistoryindex" /> </bean> - <bean id="attributeUpdater" class="org.onap.aai.sparky.editattributes.AttributeUpdater"> - <constructor-arg ref="oxmModelLoader" /> - <constructor-arg ref="oxmEntityLookup" /> - <constructor-arg ref="activeInventoryAdapter" /> - </bean> - - <bean id="attributeEditProcessor" - class="org.onap.aai.sparky.editattributes.AttributeEditProcessor"> - <constructor-arg ref="attributeUpdater" /> - </bean> - <bean id="geoVisualizationProcessor" class="org.onap.aai.sparky.inventory.GeoVisualizationProcessor"> <constructor-arg ref="elasticSearchAdapter" /> <constructor-arg name="topographicalSearchIndexName" diff --git a/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users-empty.config b/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users-empty.config deleted file mode 100644 index e69de29..0000000 --- a/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users-empty.config +++ /dev/null diff --git a/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users.config b/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users.config deleted file mode 100644 index b9bb4e2..0000000 --- a/sparkybe-onap-service/src/test/resources/user-auth-reader/authorized-users.config +++ /dev/null @@ -1,3 +0,0 @@ -user1 -user2 user3 -user4
\ No newline at end of file diff --git a/sparkybe-onap-service/src/test/resources/user-validator/authorized-users.config b/sparkybe-onap-service/src/test/resources/user-validator/authorized-users.config deleted file mode 100644 index 58698bc..0000000 --- a/sparkybe-onap-service/src/test/resources/user-validator/authorized-users.config +++ /dev/null @@ -1,3 +0,0 @@ - user1 -user2 user3 -user4
\ No newline at end of file |