Merge "Prevent adding same type of Op policy"
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index ca3681b..3f568a3 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -118,6 +118,12 @@
     Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) throws IOException {
         Loop loop = getLoop(loopName);
         PolicyModel policyModel = policyModelsService.getPolicyModel(policyType, policyVersion);
+        Set<OperationalPolicy> opPolicySet = loop.getOperationalPolicies();
+        for (OperationalPolicy opPolicy : opPolicySet) {
+        	if (opPolicy.getPolicyModel().equals(policyModel)) {
+        		throw new IllegalArgumentException("This type of Operational Policy is already added to the loop. Please choose another one.");
+        	}
+        }
         if (policyModel == null) {
             return null;
         }
diff --git a/ui-react/src/api/LoopService.js b/ui-react/src/api/LoopService.js
index f10d187..3b9ed86 100644
--- a/ui-react/src/api/LoopService.js
+++ b/ui-react/src/api/LoopService.js
@@ -226,18 +226,17 @@
 			credentials: 'same-origin'
 		})
 				.then(function (response) {
-					console.debug("Add Operational Policy response received: ", response.status);
+				console.debug("Add Operational Policy response received: ", response.status);
 				if (response.ok) {
 					return response.json();
 				} else {
-					console.error("Add Operational Policy query failed");
-					return {};
+					return response.text();
 				}
 			})
-			.catch(function (error) {
-				console.error("Add Operational Policy error received", error);
-				return {};
-			});
+			.then(function (object) {
+				console.error("Add Operational Policy query failed");
+				throw new Error(object);
+			})
 	}
 
 	static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) {
diff --git a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
index 8c67405..5154a88 100644
--- a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
+++ b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
@@ -37,7 +37,7 @@
 import LoopService from '../../../api/LoopService';
 import Tabs from 'react-bootstrap/Tabs';
 import Tab from 'react-bootstrap/Tab';
-
+import Alert from 'react-bootstrap/Alert';
 
 const ModalStyled = styled(Modal)`
 	background-color: transparent;
@@ -65,6 +65,7 @@
 		toscaPolicyModelsData: [],
 		selectedPolicyModelsData: [],
 		key: 'add',
+		showFailAlert: false,
 		toscaColumns: [
 			{ title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
 				cellStyle: cellStyle,
@@ -166,10 +167,25 @@
 		this.props.history.push('/');
 	}
 
+	renderAlert() {
+		return (
+			<div>
+				<Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
+					{this.state.showMessage}
+				</Alert>
+			</div>
+		);
+	}
+
 	handleAdd() {
-		LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version);
-		this.props.loadLoopFunction(this.state.loopCache.getLoopName());
-		this.handleClose();
+		LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version)
+		.then(pars => {
+			this.props.loadLoopFunction(this.state.loopCache.getLoopName());
+			this.handleClose();
+		})
+		.catch(error => {
+			this.setState({ showFailAlert: true, showMessage: "Adding failed with error: " + error.message});
+		});
 	}
 
 	handleRemove() {
@@ -198,13 +214,14 @@
 								rowStyle: rowData => ({
 									backgroundColor: (this.state.selectedRowData !== {} && this.state.selectedRowData.tableData !== undefined
 									&& this.state.selectedRowData.tableData.id === rowData.tableData.id) ? '#EEE' : '#FFF'
-								})
+									})
 							}}
 							/>
 							<div>
 								<TextModal value={this.state.content} onChange={this.handleYamlContent}/>
 							</div>
 						</Modal.Body>
+						{this.renderAlert()}
 					</Tab>
 					<Tab eventKey="remove" title="Remove Operational Policies">
 						<Modal.Body>