Commit 1 - Fixup Create Opt API 73/83373/1
authorJerry Flood <jflood@att.com>
Tue, 26 Mar 2019 15:25:05 +0000 (11:25 -0400)
committerJerry Flood <jflood@att.com>
Tue, 26 Mar 2019 15:35:29 +0000 (11:35 -0400)
Issue-ID: OPTFRA-458

Change-Id: Iad684cd51429d606f006d29386263ad179193b62
Signed-off-by: Jerry Flood <jflood@att.com>
cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java [deleted file]
cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java [new file with mode: 0644]
cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java
cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java
cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java [deleted file]
cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java [deleted file]
cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java
cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java [new file with mode: 0644]
cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java [new file with mode: 0644]
cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizerCallback.java [moved from cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java with 96% similarity]

diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java b/cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java
deleted file mode 100644 (file)
index 8b37a71..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*\r
- * Copyright © 2017-2019 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
-\r
-package org.onap.optf.cmso.filters;\r
-\r
-import java.io.IOException;\r
-import java.util.UUID;\r
-\r
-import javax.annotation.Priority;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.WebApplicationException;\r
-import javax.ws.rs.container.ContainerRequestContext;\r
-import javax.ws.rs.container.ContainerRequestFilter;\r
-import javax.ws.rs.container.ContainerResponseContext;\r
-import javax.ws.rs.container.ContainerResponseFilter;\r
-import javax.ws.rs.core.Context;\r
-import javax.ws.rs.core.MultivaluedMap;\r
-import javax.ws.rs.core.Response;\r
-import javax.ws.rs.core.Response.ResponseBuilder;\r
-import javax.ws.rs.ext.Provider;\r
-\r
-import org.onap.observations.Mdc;\r
-import org.onap.observations.Observation;\r
-import org.onap.optf.cmso.common.LogMessages;\r
-import org.onap.optf.cmso.filters.MessageHeaders.HeadersEnum;\r
-import org.springframework.stereotype.Component;\r
-\r
-@Priority(1)\r
-@Provider\r
-@Component\r
-public class CMSOContainerFilters implements ContainerRequestFilter, ContainerResponseFilter {\r
-\r
-\r
-       @Context\r
-       private HttpServletRequest servletRequest;\r
-\r
-    @Override\r
-    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)\r
-            throws IOException {\r
-        try {\r
-                       Mdc.auditEnd(requestContext, responseContext);\r
-                       Observation.report(LogMessages.INCOMING_MESSAGE_RESPONSE, \r
-                                       requestContext.getMethod(),\r
-                                       requestContext.getUriInfo().getPath().toString(),\r
-                                       responseContext.getStatusInfo().toString());\r
-            MultivaluedMap<String, String> reqHeaders = requestContext.getHeaders();\r
-            MultivaluedMap<String, Object> respHeaders = responseContext.getHeaders();\r
-            String minorVersion = (String) reqHeaders.getFirst(HeadersEnum.MinorVersion.toString());\r
-            respHeaders.add(HeadersEnum.MinorVersion.toString(), minorVersion);\r
-            respHeaders.add(HeadersEnum.LatestVersion.toString(), MessageHeaders.latestVersion);\r
-            respHeaders.add(HeadersEnum.PatchVersion.toString(), MessageHeaders.patchVersion);\r
-\r
-        } catch (Exception e) {\r
-            if (e instanceof WebApplicationException) {\r
-               Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());\r
-            } else {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());\r
-            }\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void filter(ContainerRequestContext requestContext) throws IOException {\r
-        try {\r
-            // On the way in\r
-                       Mdc.auditStart(requestContext, servletRequest);\r
-                       Observation.report(LogMessages.INCOMING_MESSAGE, \r
-                                       requestContext.getMethod(),\r
-                                       requestContext.getUriInfo().getPath().toString());\r
-\r
-            String majorVersion = requestContext.getUriInfo().getPath();\r
-            if (majorVersion != null) {\r
-\r
-                if (majorVersion.startsWith("dispatch/"))\r
-                    return;\r
-                majorVersion = majorVersion.replaceAll("/.*$", "");\r
-            }\r
-            if (!MessageHeaders.validateMajorVersion(majorVersion)) {\r
-                ResponseBuilder builder = null;\r
-                String response = "Unsupported Major version";\r
-                builder = Response.status(Response.Status.NOT_FOUND).entity(response);\r
-                throw new WebApplicationException(builder.build());\r
-            }\r
-            MultivaluedMap<String, String> headers = requestContext.getHeaders();\r
-            String transactionId = (String) headers.getFirst(HeadersEnum.TransactionID.toString());\r
-            if (transactionId == null) {\r
-                transactionId = UUID.randomUUID().toString();\r
-                headers.add(HeadersEnum.TransactionID.toString(), transactionId);\r
-            }\r
-            String minorVersion = (String) headers.getFirst(HeadersEnum.MinorVersion.toString());\r
-            if (minorVersion == null) {\r
-                minorVersion = MessageHeaders.supportedMajorVersions.get(majorVersion);\r
-                headers.add(HeadersEnum.MinorVersion.toString(), minorVersion);\r
-            }\r
-            if (!MessageHeaders.validateMajorMinorVersion(majorVersion, minorVersion)) {\r
-                ResponseBuilder builder = null;\r
-                String response = "Unsupported API version";\r
-                builder = Response.status(Response.Status.NOT_FOUND).entity(response);\r
-                throw new WebApplicationException(builder.build());\r
-\r
-            }\r
-        } catch (Exception e) {\r
-            if (e instanceof WebApplicationException) {\r
-                Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());\r
-                throw e;\r
-            } else {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-}\r
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java b/cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java
new file mode 100644 (file)
index 0000000..00b8fe5
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.filters;
+
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+import org.onap.observations.Mdc;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.filters.MessageHeaders.HeadersEnum;
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+
+// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+@Component
+public class CmsoClientFilters implements ClientRequestFilter, ClientResponseFilter {
+
+    private static EELFLogger log = EELFManager.getInstance().getLogger(CmsoClientFilters.class);
+    private static String appId = "cmso";
+
+    @Override
+    public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+               // On the way back
+               Mdc.metricEnd(responseContext);
+               Mdc.setCaller(17);
+               Observation.report(LogMessages.OUTGOING_MESSAGE_RETURNED,
+                               requestContext.getMethod(),
+                               requestContext.getUri().getPath().toString(),
+                               responseContext.getStatusInfo().toString());
+    }
+
+    @Override
+    public void filter(ClientRequestContext requestContext) throws IOException {
+               // On the way out
+               Mdc.metricStart(requestContext);
+               Mdc.setCaller(17);
+               Observation.report(LogMessages.OUTGOING_MESSAGE,
+                               requestContext.getMethod(),
+                               requestContext.getUri().getPath().toString());
+        MultivaluedMap<String, Object> headers = requestContext.getHeaders();
+
+        String transactionId = (String) headers.getFirst(MessageHeaders.HeadersEnum.TransactionID.toString());
+        String mdcId = MDC.get(MDC_KEY_REQUEST_ID);
+        if (transactionId == null || transactionId.equals(""))
+            if (mdcId != null)
+                headers.add(HeadersEnum.TransactionID.toString(), mdcId);
+        headers.add(HeadersEnum.FromAppID.toString(), appId);
+    }
+
+}
index 6009040..677f5ce 100644 (file)
@@ -1,39 +1,33 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.model;\r
 \r
 import java.io.Serializable;\r
 import java.util.UUID;\r
-\r
 import javax.persistence.Column;\r
 import javax.persistence.Entity;\r
 import javax.persistence.Id;\r
@@ -42,7 +36,7 @@ import javax.persistence.Table;
 \r
 /**\r
  * The persistent class for the approval_types database table.\r
- * \r
+ *\r
  */\r
 @Entity\r
 @Table(name = "APPROVAL_TYPES")\r
@@ -63,39 +57,82 @@ public class ApprovalType implements Serializable {
     @Column(name = "domain")\r
     private String domain;\r
 \r
+    /**\r
+     * Instantiates a new approval type.\r
+     */\r
     public ApprovalType() {}\r
 \r
 \r
+    /**\r
+     * Gets the uuid.\r
+     *\r
+     * @return the uuid\r
+     */\r
     public UUID getUuid() {\r
-               return uuid;\r
-       }\r
+        return uuid;\r
+    }\r
 \r
 \r
-       public void setUuid(UUID uuid) {\r
-               this.uuid = uuid;\r
-       }\r
+    /**\r
+     * Sets the uuid.\r
+     *\r
+     * @param uuid the new uuid\r
+     */\r
+    public void setUuid(UUID uuid) {\r
+        this.uuid = uuid;\r
+    }\r
 \r
 \r
-       public Integer getApprovalCount() {\r
+    /**\r
+     * Gets the approval count.\r
+     *\r
+     * @return the approval count\r
+     */\r
+    public Integer getApprovalCount() {\r
         return this.approvalCount;\r
     }\r
 \r
+    /**\r
+     * Sets the approval count.\r
+     *\r
+     * @param approvalCount the new approval count\r
+     */\r
     public void setApprovalCount(Integer approvalCount) {\r
         this.approvalCount = approvalCount;\r
     }\r
 \r
+    /**\r
+     * Gets the approval type.\r
+     *\r
+     * @return the approval type\r
+     */\r
     public String getApprovalType() {\r
         return this.approvalType;\r
     }\r
 \r
+    /**\r
+     * Sets the approval type.\r
+     *\r
+     * @param approvalType the new approval type\r
+     */\r
     public void setApprovalType(String approvalType) {\r
         this.approvalType = approvalType;\r
     }\r
 \r
+    /**\r
+     * Gets the domain.\r
+     *\r
+     * @return the domain\r
+     */\r
     public String getDomain() {\r
         return domain;\r
     }\r
 \r
+    /**\r
+     * Sets the domain.\r
+     *\r
+     * @param domain the new domain\r
+     */\r
     public void setDomain(String domain) {\r
         this.domain = domain;\r
     }\r
index 210e61a..f0b1da1 100644 (file)
@@ -1,57 +1,48 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.model;\r
 \r
+import com.fasterxml.jackson.annotation.JsonIgnore;\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import io.swagger.annotations.ApiModel;\r
+import io.swagger.annotations.ApiModelProperty;\r
 import java.io.Serializable;\r
 import java.util.UUID;\r
-\r
 import javax.persistence.Column;\r
 import javax.persistence.Entity;\r
 import javax.persistence.Id;\r
 import javax.persistence.NamedQuery;\r
 import javax.persistence.Table;\r
 import javax.persistence.Transient;\r
-\r
 import org.joda.time.format.ISODateTimeFormat;\r
 \r
-import com.fasterxml.jackson.annotation.JsonIgnore;\r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
-\r
-import io.swagger.annotations.ApiModel;\r
-import io.swagger.annotations.ApiModelProperty;\r
-\r
 /**\r
  * The persistent class for the change_management_change_windows database table.\r
- * \r
+ *\r
  */\r
 @Entity\r
 @Table(name = "CHANGE_MANAGEMENT_CHANGE_WINDOWS")\r
@@ -86,59 +77,124 @@ public class ChangeManagementChangeWindow implements Serializable {
     @Column(name = "change_management_group_uuid")\r
     private UUID changeManagementGroupUuid;\r
 \r
+    /**\r
+     * Instantiates a new change management change window.\r
+     */\r
     public ChangeManagementChangeWindow() {}\r
 \r
 \r
+    /**\r
+     * Gets the finish time.\r
+     *\r
+     * @return the finish time\r
+     */\r
     public String getFinishTime() {\r
-        if (finishTimeMillis != null)\r
+        if (finishTimeMillis != null) {\r
             return ISODateTimeFormat.dateTimeNoMillis().print(this.finishTimeMillis);\r
+        }\r
         return null;\r
     }\r
 \r
+    /**\r
+     * Sets the finish time.\r
+     *\r
+     * @param finishTime the new finish time\r
+     */\r
     public void setFinishTime(String finishTime) {}\r
 \r
+    /**\r
+     * Gets the start time.\r
+     *\r
+     * @return the start time\r
+     */\r
     public String getStartTime() {\r
-        if (startTimeMillis != null)\r
+        if (startTimeMillis != null) {\r
             return ISODateTimeFormat.dateTimeNoMillis().print(this.startTimeMillis);\r
+        }\r
         return null;\r
     }\r
 \r
+    /**\r
+     * Sets the start time.\r
+     *\r
+     * @param startTime the new start time\r
+     */\r
     public void setStartTime(String startTime) {}\r
 \r
 \r
+    /**\r
+     * Gets the uuid.\r
+     *\r
+     * @return the uuid\r
+     */\r
     public UUID getUuid() {\r
-               return uuid;\r
-       }\r
+        return uuid;\r
+    }\r
 \r
 \r
-       public void setUuid(UUID uuid) {\r
-               this.uuid = uuid;\r
-       }\r
+    /**\r
+     * Sets the uuid.\r
+     *\r
+     * @param uuid the new uuid\r
+     */\r
+    public void setUuid(UUID uuid) {\r
+        this.uuid = uuid;\r
+    }\r
 \r
 \r
 \r
-       public UUID getChangeManagementGroupUuid() {\r
-               return changeManagementGroupUuid;\r
-       }\r
+    /**\r
+     * Gets the change management group uuid.\r
+     *\r
+     * @return the change management group uuid\r
+     */\r
+    public UUID getChangeManagementGroupUuid() {\r
+        return changeManagementGroupUuid;\r
+    }\r
 \r
 \r
-       public void setChangeManagementGroupUuid(UUID changeManagementGroupUuid) {\r
-               this.changeManagementGroupUuid = changeManagementGroupUuid;\r
-       }\r
+    /**\r
+     * Sets the change management group uuid.\r
+     *\r
+     * @param changeManagementGroupUuid the new change management group uuid\r
+     */\r
+    public void setChangeManagementGroupUuid(UUID changeManagementGroupUuid) {\r
+        this.changeManagementGroupUuid = changeManagementGroupUuid;\r
+    }\r
 \r
 \r
-       public Long getFinishTimeMillis() {\r
+    /**\r
+     * Gets the finish time millis.\r
+     *\r
+     * @return the finish time millis\r
+     */\r
+    public Long getFinishTimeMillis() {\r
         return finishTimeMillis;\r
     }\r
 \r
+    /**\r
+     * Sets the finish time millis.\r
+     *\r
+     * @param finishTimeMillis the new finish time millis\r
+     */\r
     public void setFinishTimeMillis(Long finishTimeMillis) {\r
         this.finishTimeMillis = finishTimeMillis;\r
     }\r
 \r
+    /**\r
+     * Gets the start time millis.\r
+     *\r
+     * @return the start time millis\r
+     */\r
     public Long getStartTimeMillis() {\r
         return startTimeMillis;\r
     }\r
 \r
+    /**\r
+     * Sets the start time millis.\r
+     *\r
+     * @param startTimeMillis the new start time millis\r
+     */\r
     public void setStartTimeMillis(Long startTimeMillis) {\r
         this.startTimeMillis = startTimeMillis;\r
     }\r
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java
deleted file mode 100644 (file)
index a773798..0000000
+++ /dev/null
@@ -1,373 +0,0 @@
-/*\r
- * Copyright © 2017-2019 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
-\r
-package org.onap.optf.cmso.optimizer;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.UUID;\r
-\r
-import javax.ws.rs.ProcessingException;\r
-import javax.ws.rs.client.Client;\r
-import javax.ws.rs.client.ClientBuilder;\r
-import javax.ws.rs.client.Entity;\r
-import javax.ws.rs.client.Invocation;\r
-import javax.ws.rs.client.ResponseProcessingException;\r
-import javax.ws.rs.client.WebTarget;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
-\r
-import org.onap.observations.Mdc;\r
-import org.onap.observations.Observation;\r
-import org.onap.optf.cmso.common.BasicAuthenticatorFilter;\r
-import org.onap.optf.cmso.common.CMSStatusEnum;\r
-import org.onap.optf.cmso.common.LogMessages;\r
-import org.onap.optf.cmso.common.PropertiesManagement;\r
-import org.onap.optf.cmso.filters.CMSOClientFilters;\r
-import org.onap.optf.cmso.model.Schedule;\r
-import org.onap.optf.cmso.model.dao.ScheduleDAO;\r
-import org.onap.optf.cmso.optimizer.bean.CMOptimizerRequest;\r
-import org.onap.optf.cmso.optimizer.bean.CMRequestInfo;\r
-import org.onap.optf.cmso.optimizer.bean.CMSchedulingInfo;\r
-import org.onap.optf.cmso.optimizer.bean.CMVnfDetails;\r
-import org.onap.optf.cmso.service.rs.models.CMSInfo;\r
-import org.onap.optf.cmso.service.rs.models.ChangeWindowMessage;\r
-import org.onap.optf.cmso.service.rs.models.HealthCheckComponent;\r
-import org.onap.optf.cmso.service.rs.models.VnfDetailsMessage;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.core.env.Environment;\r
-import org.springframework.stereotype.Component;\r
-import org.springframework.transaction.annotation.Transactional;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-\r
-@Component\r
-public class CMSOptimizerClient {\r
-    private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
-\r
-    @Autowired\r
-    ScheduleDAO scheduleDAO;\r
-\r
-    @Autowired\r
-    Environment env;\r
-\r
-    @Autowired\r
-    PropertiesManagement pm;\r
-\r
-    public boolean scheduleOptimization(UUID uuid) {\r
-        Map<String, String> mdcSave = Mdc.save();\r
-        try {\r
-            String optimizerurl = env.getProperty("cmso.optimizer.url");\r
-            String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");\r
-            String username = env.getProperty("mechid.user");\r
-            Integer maxAttempts = env.getProperty("cmso.optimizer.maxAttempts", Integer.class, 20);\r
-\r
-            // Ensure that only one cmso is requsting this call to optimizer\r
-            Schedule schedule = scheduleDAO.lockOne(uuid);\r
-            if (!schedule.getStatus().equals(CMSStatusEnum.PendingSchedule.toString()))\r
-                return false;\r
-\r
-            String password = pm.getProperty("mechid.pass", "");\r
-            //\r
-            // Only 'successfully' process one schedule per invocation\r
-            // If a schedule attemp fails and it could be because of the data in the\r
-            // message, try the next one. We don't want bad data to\r
-            //\r
-            if (schedule.getOptimizerAttemptsToSchedule() >= maxAttempts) {\r
-                schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());\r
-                schedule.setOptimizerMessage("Maximum number of attempts exceeded " + maxAttempts);\r
-                updateScheduleStatus(schedule);\r
-                return true;\r
-            }\r
-            CMOptimizerRequest cmReq = new CMOptimizerRequest();\r
-            try {\r
-                CMSInfo info = reconstituteMessage(schedule);\r
-                if (info == null) {\r
-                    return true;\r
-                }\r
-                buildRequest(cmReq, info, schedule, optimizercallbackurl);\r
-            } catch (Exception e) {\r
-                Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-                schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());\r
-                schedule.setOptimizerMessage("Unexpected exception: " + e.getMessage());\r
-                updateScheduleStatus(schedule);\r
-                return true;\r
-            }\r
-\r
-            // This service will call SNIO for each PendingOptimiztion\r
-            // If the request is successfully scheduled in optimizer, status will be\r
-            // updated to OptimizationInProgress.\r
-            Client client = ClientBuilder.newClient();\r
-            client.register(new BasicAuthenticatorFilter(username, password));\r
-            client.register(new CMSOClientFilters());\r
-            WebTarget optimizerTarget = client.target(optimizerurl);\r
-            Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);\r
-            try {\r
-                //\r
-                // First, push OptimizationInProgress to the DB (flush()) assuming a 202 status,\r
-                // in case the optimizer callback is received prior to the\r
-                // commit of this transaction.\r
-                // optimizer Callback will throw an error if it receives a response in the incorrect\r
-                // state.\r
-                //\r
-                schedule.setOptimizerTransactionId(cmReq.getRequestInfo().getTransactionId());\r
-                schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-                schedule.setStatus(CMSStatusEnum.OptimizationInProgress.toString());\r
-                updateScheduleStatus(schedule);\r
-                debug.debug("optimizer url / user: " + optimizerurl + " / " + username);\r
-                debug.debug("optimizer Request: " + new ObjectMapper().writeValueAsString(cmReq));\r
-                Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", schedule.getScheduleId(), optimizerurl);\r
-                Response response = invocationBuilder.post(Entity.json(cmReq));\r
-                Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", schedule.getScheduleId(), optimizerurl);\r
-                switch (response.getStatus()) {\r
-                    case 202:\r
-                        debug.debug("Successfully scheduled optimization: " + schedule.getScheduleId());\r
-                        // Scheduled with optimizer\r
-                        break;\r
-                    case 400: // Bad request\r
-                    {\r
-                        schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-                        schedule.setOptimizerStatus("HTTP Status: " + response.getStatus());\r
-                        String message = response.readEntity(String.class);\r
-                        schedule.setOptimizerMessage(message);\r
-                        schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());\r
-                        // Need to understand the cause of this error. May be teh same as optimizer\r
-                        // down.\r
-                        int tries = schedule.getOptimizerAttemptsToSchedule();\r
-                        tries++;\r
-                        schedule.setOptimizerAttemptsToSchedule(tries);\r
-                        updateScheduleStatus(schedule);\r
-                        Observation.report(LogMessages.OPTIMIZER_EXCEPTION, message);\r
-                        return true;\r
-                    }\r
-\r
-                    case 500:\r
-                    default: {\r
-                        String message = response.readEntity(String.class);\r
-                        // SHould probably track the number of retries.\r
-                        schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-                        int tries = schedule.getOptimizerAttemptsToSchedule();\r
-                        tries++;\r
-                        schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());\r
-                        schedule.setOptimizerAttemptsToSchedule(tries);\r
-                        schedule.setOptimizerMessage(message);\r
-                        updateScheduleStatus(schedule);\r
-                        /// Got processing error response\r
-                        // may be transient, wait for next cycle.\r
-                        Observation.report(LogMessages.OPTIMIZER_EXCEPTION, message);\r
-                        // Wait until next cycle and try again.\r
-                        return false;\r
-                    }\r
-\r
-                }\r
-                //\r
-                return true;\r
-            } catch (ResponseProcessingException e) {\r
-                schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-                schedule.setOptimizerStatus("Failed to parse optimizer response");\r
-                schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());\r
-                // Need to understand the cause of this error. May be teh same as optimizer down.\r
-                int tries = schedule.getOptimizerAttemptsToSchedule();\r
-                tries++;\r
-                schedule.setOptimizerAttemptsToSchedule(tries);\r
-                updateScheduleStatus(schedule);\r
-                // Getting invalid response from optimizer.\r
-                // May be data related.\r
-                Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());\r
-                return false;\r
-\r
-            } catch (ProcessingException e) {\r
-                // Don't track number of retries on IO error (optimizer is down)\r
-                schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-                schedule.setStatus(CMSStatusEnum.PendingSchedule.toString());\r
-                updateScheduleStatus(schedule);\r
-                /// Cannot connect to optimizer\r
-                Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());\r
-                // Wait until next cycle\r
-                return false;\r
-            }\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-\r
-        } finally {\r
-            Mdc.restore(mdcSave);\r
-        }\r
-        return false;\r
-    }\r
-\r
-    private void buildRequest(CMOptimizerRequest cmReq, CMSInfo info, Schedule schedule, String optimizercallbackurl) {\r
-\r
-        // TODO: Need to get optimizer to accept ChangeManagementSchedulingInfo\r
-        // This is to support 1707 optimizer interface\r
-        CMRequestInfo reqInfo = cmReq.getRequestInfo();\r
-        CMSchedulingInfo schInfo = cmReq.getSchedulingInfo();\r
-\r
-        UUID uuid = UUID.randomUUID();\r
-        reqInfo.setCallbackUrl(optimizercallbackurl);\r
-        reqInfo.setOptimizer(new String[] {"scheduling"});\r
-        reqInfo.setTransactionId(schedule.getOptimizerTransactionId());\r
-        reqInfo.setRequestId("CM-" + uuid.toString());\r
-        reqInfo.setSourceId("cmso");\r
-\r
-        String[] policyArray = new String[1];\r
-        policyArray[0] = info.getPolicyId();\r
-        schInfo.setPolicyId(policyArray);\r
-        schInfo.setAdditionalDurationInSecs(info.getAdditionalDurationInSeconds());\r
-        schInfo.setConcurrencyLimit(info.getConcurrencyLimit());\r
-        schInfo.setNormalDurationInSecs(info.getNormalDurationInSeconds());\r
-        schInfo.setScheduleId(schedule.getScheduleId());\r
-        List<CMVnfDetails> list = new ArrayList<CMVnfDetails>();\r
-        String startTime = "";\r
-        String endTime = "";\r
-\r
-        for (VnfDetailsMessage vnf : info.getVnfDetails()) {\r
-            String groupId = vnf.getGroupId();\r
-            for (String node : vnf.getNode()) {\r
-                CMVnfDetails d = new CMVnfDetails(vnf.getGroupId());\r
-                d.setNode(node);\r
-                list.add(d);\r
-            }\r
-            if (startTime.equals("")) {\r
-                // Only supporting 1 CW for 1710\r
-                ChangeWindowMessage cw = vnf.getChangeWindow().get(0);\r
-                startTime = cw.getStartTime();\r
-                endTime = cw.getEndTime();\r
-            }\r
-        }\r
-        schInfo.setStartTime(startTime);\r
-        schInfo.setEndTime(endTime);\r
-        schInfo.setVnfDetails(list.toArray(new CMVnfDetails[list.size()]));\r
-\r
-    }\r
-\r
-    private CMSInfo reconstituteMessage(Schedule schedule) {\r
-        String request = schedule.getScheduleInfo();\r
-        ObjectMapper om = new ObjectMapper();\r
-        try {\r
-            CMSInfo info = om.readValue(request, CMSInfo.class);\r
-            return info;\r
-        } catch (Exception e) {\r
-            // Parsing should work here because this was a toString on the original object.\r
-            // We may have an issue when upgrading....\r
-            // Perhaps We create ChangeManagementSchedulingInfoV1, ...V2, etc.\r
-            // ANd try them one after another....\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, "Unable to parse message. Format changed?");\r
-            schedule.setOptimizerStatus("Failed to parse optimizer request");\r
-            schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());\r
-            schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());\r
-            scheduleDAO.save(schedule);\r
-        }\r
-        return null;\r
-    }\r
-\r
-    @Transactional\r
-    public void updateScheduleStatus(Schedule schedule) {\r
-        scheduleDAO.save(schedule);\r
-\r
-    }\r
-\r
-    public HealthCheckComponent healthCheck() {\r
-        Map<String, String> mdcSave = Mdc.save();\r
-        HealthCheckComponent hcc = new HealthCheckComponent();\r
-        hcc.setName("OPtimizer Interface");\r
-        String optimizerurl = env.getProperty("cmso.optimizer.url");\r
-        String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");\r
-        String username = env.getProperty("mechid.user");\r
-        String password = pm.getProperty("mechid.pass", "");\r
-        hcc.setUrl(optimizerurl);\r
-        try {\r
-            UUID uuid = UUID.randomUUID();\r
-            // Build a bogus request should fail policy validation\r
-            CMRequestInfo requestInfo = new CMRequestInfo();\r
-            CMSchedulingInfo schedulingInfo = new CMSchedulingInfo();\r
-            CMOptimizerRequest cmReq = new CMOptimizerRequest();\r
-            cmReq.setRequestInfo(requestInfo);\r
-            cmReq.setSchedulingInfo(schedulingInfo);\r
-            requestInfo.setCallbackUrl("http://callbackurl.onap.org:8080/healthcheck");\r
-            requestInfo.setOptimizer(new String[] {"scheduling"});\r
-            requestInfo.setTransactionId(uuid.toString());\r
-            requestInfo.setRequestId("CM-" + uuid.toString());\r
-            requestInfo.setSourceId("cmso");\r
-            schedulingInfo.setAdditionalDurationInSecs(10);\r
-            schedulingInfo.setConcurrencyLimit(10);\r
-            schedulingInfo.setNormalDurationInSecs(10);\r
-            schedulingInfo.setPolicyId(new String[] {"healthcheck"});\r
-            schedulingInfo.setScheduleId(uuid.toString());\r
-            CMVnfDetails details = new CMVnfDetails();\r
-            details.setGroupId("");\r
-            details.setNode("healtcheck");\r
-            schedulingInfo.setVnfDetails(new CMVnfDetails[] {details});\r
-            schedulingInfo.setStartTime("2017-12-11T15:23:24Z");\r
-            schedulingInfo.setEndTime("2017-12-11T22:23:24Z");\r
-\r
-            Client client = ClientBuilder.newClient();\r
-            client.register(new BasicAuthenticatorFilter(username, password));\r
-            client.register(new CMSOClientFilters());\r
-\r
-            WebTarget optimizerTarget = client.target(optimizerurl);\r
-            Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);\r
-            debug.debug("Optimizer url / user: " + optimizerurl + " / " + username);\r
-            Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", "healthcheck", optimizerurl);\r
-            Response response = invocationBuilder.post(Entity.json(cmReq));\r
-            Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", "healthcheck", optimizerurl);\r
-            String message = response.getStatus() + ":" + response.readEntity(String.class);\r
-            switch (response.getStatus()) {\r
-                case 202:\r
-                    debug.debug("Successful optimizer healthcheck");\r
-                    hcc.setHealthy(true);\r
-                    break;\r
-                case 400:\r
-                    // Expecting policy not found.\r
-                    if (message.contains("Cannot fetch policy")) {\r
-                        debug.debug("Successful optimizer healthcheck");\r
-                        hcc.setHealthy(true);\r
-                        hcc.setStatus("OK");\r
-                    } else {\r
-                        hcc.setStatus(message);\r
-                    }\r
-                    break;\r
-                default:\r
-                    hcc.setStatus(message);\r
-                    break;\r
-            }\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.toString());\r
-            hcc.setStatus(e.toString());\r
-        } finally {\r
-            Mdc.restore(mdcSave);\r
-        }\r
-        return hcc;\r
-\r
-    }\r
-}\r
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java
deleted file mode 100644 (file)
index cc304db..0000000
+++ /dev/null
@@ -1,681 +0,0 @@
-/*\r
- * Copyright © 2017-2019 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
-\r
-package org.onap.optf.cmso.service.rs;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.TimeZone;\r
-import java.util.UUID;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.core.MultivaluedMap;\r
-import javax.ws.rs.core.Response;\r
-import javax.ws.rs.core.Response.Status;\r
-import javax.ws.rs.core.UriInfo;\r
-\r
-import org.joda.time.DateTime;\r
-import org.onap.observations.Observation;\r
-import org.onap.optf.cmso.common.ApprovalStatusEnum;\r
-import org.onap.optf.cmso.common.ApprovalTypesEnum;\r
-import org.onap.optf.cmso.common.CMSStatusEnum;\r
-import org.onap.optf.cmso.common.DomainsEnum;\r
-import org.onap.optf.cmso.common.LogMessages;\r
-import org.onap.optf.cmso.common.exceptions.CMSException;\r
-import org.onap.optf.cmso.common.exceptions.CMSNotFoundException;\r
-import org.onap.optf.cmso.eventq.CMSQueueJob;\r
-import org.onap.optf.cmso.model.ChangeManagementChangeWindow;\r
-import org.onap.optf.cmso.model.ChangeManagementDetail;\r
-import org.onap.optf.cmso.model.ChangeManagementGroup;\r
-import org.onap.optf.cmso.model.ChangeManagementSchedule;\r
-import org.onap.optf.cmso.model.DomainData;\r
-import org.onap.optf.cmso.model.Schedule;\r
-import org.onap.optf.cmso.model.ScheduleQuery;\r
-import org.onap.optf.cmso.model.dao.ChangeManagementChangeWindowDAO;\r
-import org.onap.optf.cmso.model.dao.ChangeManagementDetailDAO;\r
-import org.onap.optf.cmso.model.dao.ChangeManagementGroupDAO;\r
-import org.onap.optf.cmso.model.dao.ChangeManagementScheduleDAO;\r
-import org.onap.optf.cmso.model.dao.ScheduleDAO;\r
-import org.onap.optf.cmso.model.dao.ScheduleQueryDAO;\r
-import org.onap.optf.cmso.service.rs.models.ApprovalMessage;\r
-import org.onap.optf.cmso.service.rs.models.CMSInfo;\r
-import org.onap.optf.cmso.service.rs.models.CMSMessage;\r
-import org.onap.optf.cmso.service.rs.models.ChangeWindowMessage;\r
-import org.onap.optf.cmso.service.rs.models.CmDetailsMessage;\r
-import org.onap.optf.cmso.service.rs.models.CmDomainDataEnum;\r
-import org.onap.optf.cmso.service.rs.models.VnfDetailsMessage;\r
-import org.onap.optf.cmso.ticketmgt.TmClient;\r
-import org.onap.optf.cmso.ticketmgt.bean.BuildCreateRequest;\r
-import org.onap.optf.cmso.ticketmgt.bean.TmApprovalStatusEnum;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.core.env.Environment;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.transaction.annotation.Transactional;\r
-import org.springframework.transaction.interceptor.TransactionAspectSupport;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
-@Controller\r
-public class CMSOServiceImpl extends BaseSchedulerServiceImpl implements CMSOService {\r
-    private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
-\r
-    @Autowired\r
-    CMSQueueJob qJob;\r
-\r
-    @Autowired\r
-    Environment env;\r
-\r
-    @Autowired\r
-    ChangeManagementScheduleDAO cmScheduleDAO;\r
-\r
-    @Autowired\r
-    ChangeManagementGroupDAO cmGroupDAO;\r
-\r
-    @Autowired\r
-    ChangeManagementChangeWindowDAO cmChangeWindowDAO;\r
-\r
-    @Autowired\r
-    ChangeManagementDetailDAO cmDetailsDAO;\r
-\r
-    @Autowired\r
-    ScheduleQueryDAO scheduleQueryDAO;\r
-\r
-    @Autowired\r
-    ScheduleDAO scheduleDAO;\r
-\r
-    @Autowired\r
-    TmClient tmClient;\r
-\r
-    @Autowired\r
-    BuildCreateRequest buildCreateRequest;\r
-\r
-    @Override\r
-    public Response searchScheduleRequests(String apiVersion, Boolean includeDetails, String scheduleId,\r
-            String scheduleName, String userId, String status, String createDateTime, String optimizerStatus,\r
-            String workflowName, UriInfo uri, HttpServletRequest request) {\r
-\r
-        Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), uri.toString(), "");\r
-        Response response = null;\r
-        List<Schedule> schedules = new ArrayList<Schedule>();\r
-        try {\r
-            debug.debug("Timezone={}", TimeZone.getDefault());\r
-            StringBuilder where = new StringBuilder();\r
-            int maxRows = 0;\r
-            //MultivaluedMap<String, String> qp = uri.getQueryParameters();\r
-            // buildWhere(qp, where);\r
-            List<ScheduleQuery> list = scheduleQueryDAO.searchSchedules(where.toString(), maxRows);\r
-            if (list == null || !list.iterator().hasNext()) {\r
-                throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,\r
-                        DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            }\r
-            Iterator<ScheduleQuery> iter = list.iterator();\r
-            while (iter.hasNext()) {\r
-                Schedule s = scheduleDAO.findById(iter.next().getUuid()).orElse(null);\r
-                if (s != null) {\r
-                    schedules.add(s);\r
-                    if (includeDetails) {\r
-                        List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getUuid());\r
-                        s.setGroups(groups);\r
-                        for (ChangeManagementGroup g : groups) {\r
-                            List<ChangeManagementSchedule> cmSchedules =\r
-                                    cmScheduleDAO.findByChangeManagementGroupId(g.getUuid());\r
-                            g.setChangeManagementSchedules(cmSchedules);\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-            response = Response.ok(schedules.toArray(new Schedule[schedules.size()])).build();\r
-        } catch (CMSException e) {\r
-               Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.serverError().build();\r
-        }\r
-\r
-        Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), schedules.toString(),\r
-                response.getStatusInfo().toString());\r
-        return response;\r
-    }\r
-\r
-    @Override\r
-    @Transactional\r
-    public Response createScheduleRequest(String apiVersion, String scheduleId, CMSMessage scheduleMessage,\r
-            HttpServletRequest request) {\r
-        Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,\r
-                scheduleMessage.toString());\r
-        Response response = null;\r
-        try {\r
-            if (!scheduleMessage.getDomain().equals(DomainsEnum.ChangeManagement.toString())) {\r
-                throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "domain",\r
-                        scheduleMessage.getDomain());\r
-            }\r
-            if (scheduleMessage.getScheduleId() == null || !scheduleMessage.getScheduleId().equals(scheduleId)) {\r
-                throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "schedulerId",\r
-                        scheduleMessage.getScheduleId());\r
-            }\r
-            // Force the name to be = to the ID because there is no way fot the provide a\r
-            // name\r
-            scheduleMessage.setScheduleName(scheduleMessage.getScheduleId());\r
-\r
-            List<DomainData> domainData = validateDomainData(scheduleMessage);\r
-            boolean immediate = validate(scheduleMessage);\r
-            Schedule schedule = validateAndAddScheduleRequest(scheduleMessage, domainData);\r
-            if (immediate) {\r
-                createChangeManagementImmediate(schedule, scheduleMessage);\r
-\r
-                // Create automatic approval\r
-                ApprovalMessage am = new ApprovalMessage();\r
-                am.setApprovalStatus(ApprovalStatusEnum.Accepted);\r
-                am.setApprovalType(ApprovalTypesEnum.Tier2);\r
-                am.setApprovalUserId(schedule.getUserId());\r
-                processApproveScheduleRequest(schedule, am, domainData);\r
-\r
-            } else {\r
-                createChangeManagement(schedule, scheduleMessage);\r
-            }\r
-            response = Response.accepted().build();\r
-        } catch (CMSException e) {\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-               Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-            response = Response.serverError().build();\r
-        }\r
-        Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,\r
-                response.getStatusInfo().toString());\r
-        return response;\r
-    }\r
-\r
-    /**\r
-     * Returns whether this is an immediate request\r
-     */\r
-    private boolean validate(CMSMessage scheduleMessage) throws CMSException {\r
-        Set<String> groups = new HashSet<String>();\r
-        CMSInfo info = scheduleMessage.getSchedulingInfo();\r
-        if (info == null) {\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_PARSE_SCHEDULING_INFO);\r
-        }\r
-\r
-        if (scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds() == null)\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                    "additionalDurationInSeconds");\r
-        if (scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds() == null)\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                    "normalDurationInSeconds");\r
-        if (scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds() < 0)\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "additionalDurationInSeconds",\r
-                    scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds().toString());\r
-        if (scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds() < 1)\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "normalDurationInSeconds",\r
-                    scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds().toString());\r
-        try {\r
-            for (VnfDetailsMessage vnfDetail : scheduleMessage.getSchedulingInfo().getVnfDetails()) {\r
-                if (vnfDetail.getChangeWindow() != null && vnfDetail.getChangeWindow().size() > 0) {\r
-                    if (vnfDetail.getNode().size() == 0) {\r
-                        throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "node list");\r
-                    }\r
-                    for (String node : vnfDetail.getNode()) {\r
-                        if (node.equals(""))\r
-                            throw new CMSException(Status.BAD_REQUEST, LogMessages.NODE_LIST_CONTAINS_EMTPY_NODE);\r
-                    }\r
-                    for (ChangeWindowMessage cw : vnfDetail.getChangeWindow()) {\r
-                        if (cw.getStartTime() == null || cw.getStartTime().equals(""))\r
-                            throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                                    "startTime");\r
-                        if (cw.getEndTime() == null || cw.getEndTime().equals(""))\r
-                            throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                                    "endTime");\r
-                        DateTime start = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");\r
-                        DateTime end = CMSOOptimizerCallbackImpl.convertISODate(cw.getEndTime(), "endTime");\r
-                        if (!end.isAfter(start))\r
-                            throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_CHANGE_WINDOW,\r
-                                    cw.getStartTime(), cw.getEndTime());\r
-                    }\r
-                    if (scheduleMessage.getSchedulingInfo().getConcurrencyLimit() == null)\r
-                        throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                                "concurrencyLimit");\r
-                    if (scheduleMessage.getSchedulingInfo().getConcurrencyLimit() < 1)\r
-                        throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "concurrencyLimit",\r
-                                scheduleMessage.getSchedulingInfo().getConcurrencyLimit().toString());\r
-                    if (scheduleMessage.getSchedulingInfo().getPolicyId() == null\r
-                            || scheduleMessage.getSchedulingInfo().getPolicyId().equals(""))\r
-                        throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "policyId");\r
-                    return false;\r
-                }\r
-                if (vnfDetail.getGroupId() == null || vnfDetail.getGroupId().equals(""))\r
-                    groups.add("default");\r
-                else\r
-                    groups.add(vnfDetail.getGroupId());\r
-            }\r
-        } catch (CMSException e) {\r
-            throw e;\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            throw new CMSException(Status.INTERNAL_SERVER_ERROR, LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());\r
-        }\r
-        // If we got here, there are no change windows....\r
-        if (groups.size() > 1)\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.MULTIPLE_GROUPS_NOT_SUPPORTED);\r
-        return true;\r
-\r
-    }\r
-\r
-    private void createChangeManagement(Schedule schedule, CMSMessage scheduleMessage) throws CMSException {\r
-        CMSInfo schedulingInfo = scheduleMessage.getSchedulingInfo();\r
-        for (VnfDetailsMessage vnfDetail : schedulingInfo.getVnfDetails()) {\r
-            ChangeManagementGroup cmg = new ChangeManagementGroup();\r
-            cmg.setUuid(UUID.randomUUID());\r
-            cmg.setSchedulesUuid(schedule.getUuid());\r
-            cmg.setGroupId("");\r
-            if (vnfDetail.getGroupId() != null)\r
-                cmg.setGroupId(vnfDetail.getGroupId());\r
-            cmg.setPolicyId(schedulingInfo.getPolicyId());\r
-            cmg.setNormalDurationInSecs(schedulingInfo.getNormalDurationInSeconds());\r
-            cmg.setAdditionalDurationInSecs(schedulingInfo.getAdditionalDurationInSeconds());\r
-            cmg.setConcurrencyLimit(schedulingInfo.getConcurrencyLimit());\r
-            cmGroupDAO.save(cmg);\r
-            for (ChangeWindowMessage cw : vnfDetail.getChangeWindow()) {\r
-                ChangeManagementChangeWindow cmcw = new ChangeManagementChangeWindow();\r
-                cmcw.setUuid(UUID.randomUUID());\r
-                cmcw.setChangeManagementGroupUuid(cmg.getUuid());\r
-                DateTime start = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");\r
-                DateTime end = CMSOOptimizerCallbackImpl.convertISODate(cw.getEndTime(), "startTime");\r
-                cmcw.setStartTimeMillis(start.getMillis());\r
-                cmcw.setFinishTimeMillis(end.getMillis());\r
-                cmChangeWindowDAO.save(cmcw);\r
-            }\r
-\r
-            for (String vnf : vnfDetail.getNode()) {\r
-                ChangeManagementSchedule cms = new ChangeManagementSchedule();\r
-                cms.setUuid(UUID.randomUUID());\r
-                cms.setChangeManagementGroupUuid(cmg.getUuid());\r
-                cms.setVnfName(vnf);\r
-                cms.setStatus(CMSStatusEnum.PendingSchedule.toString());\r
-                cmScheduleDAO.save(cms);\r
-            }\r
-        }\r
-    }\r
-\r
-    private void createChangeManagementImmediate(Schedule schedule, CMSMessage scheduleMessage) throws CMSException {\r
-        CMSInfo schedulingInfo = scheduleMessage.getSchedulingInfo();\r
-        for (VnfDetailsMessage vnfDetail : schedulingInfo.getVnfDetails()) {\r
-            ChangeManagementGroup cmg = new ChangeManagementGroup();\r
-            cmg.setUuid(UUID.randomUUID());\r
-            cmg.setSchedulesUuid(schedule.getUuid());\r
-            cmg.setGroupId("");\r
-            int duration = schedulingInfo.getNormalDurationInSeconds();\r
-            int backout = schedulingInfo.getAdditionalDurationInSeconds();\r
-            cmg.setStartTimeMillis(System.currentTimeMillis());\r
-            cmg.setFinishTimeMillis(System.currentTimeMillis() + ((duration * 1000) + (backout * 1000)));\r
-            cmg.setNormalDurationInSecs(duration);\r
-            cmg.setAdditionalDurationInSecs(backout);\r
-            if (vnfDetail.getGroupId() != null)\r
-                cmg.setGroupId(vnfDetail.getGroupId());\r
-            cmGroupDAO.save(cmg);\r
-            for (String vnf : vnfDetail.getNode()) {\r
-                ChangeManagementSchedule cms = new ChangeManagementSchedule();\r
-                cms.setUuid(UUID.randomUUID());\r
-                cms.setChangeManagementGroupUuid(cmg.getUuid());\r
-                cms.setVnfName(vnf);\r
-                cms.setStatus(CMSStatusEnum.PendingApproval.toString());\r
-                cmScheduleDAO.save(cms);\r
-            }\r
-            schedule.setStatus(CMSStatusEnum.PendingApproval.toString());\r
-            scheduleDAO.save(schedule);\r
-        }\r
-    }\r
-\r
-    private void deleteChangeManagement(Schedule schedule) throws CMSException {\r
-        List<ChangeManagementGroup> cmgs = cmGroupDAO.findBySchedulesID(schedule.getUuid());\r
-\r
-        for (ChangeManagementGroup cmg : cmgs) {\r
-            List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(cmg.getUuid());\r
-            for (ChangeManagementSchedule s : schedules) {\r
-                CMSStatusEnum currentState = CMSStatusEnum.Completed.fromString(s.getStatus());\r
-                switch (currentState) {\r
-                    case Scheduled:\r
-                        if (s.getTmChangeId() != null && !s.getTmChangeId().equals(""))\r
-                            tmClient.cancelTicket(schedule, s, s.getTmChangeId());\r
-                        s.setStatus(CMSStatusEnum.Cancelled.toString());\r
-                        break;\r
-                    case Triggered:\r
-                        // Too late...\r
-                        break;\r
-                    default:\r
-                        s.setStatus(CMSStatusEnum.Deleted.toString());\r
-                }\r
-                cmScheduleDAO.save(s);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    private List<DomainData> validateDomainData(CMSMessage scheduleMessage) throws CMSException {\r
-        List<Map<String, String>> domainData = scheduleMessage.getDomainData();\r
-        List<DomainData> domainDataList = new ArrayList<DomainData>();\r
-        Set<String> requiredFields = new HashSet<String>();\r
-        for (CmDomainDataEnum req : CmDomainDataEnum.values()) {\r
-            if (req.isRequired())\r
-                requiredFields.add(req.name());\r
-        }\r
-        for (Map<String, String> nameValue : domainData) {\r
-            for (String name : nameValue.keySet()) {\r
-                String value = nameValue.get(name);\r
-                // Save for later validation\r
-                DomainData dd = new DomainData();\r
-                dd.setName(name);\r
-                dd.setValue(value);\r
-                domainDataList.add(dd);\r
-                requiredFields.remove(name);\r
-                try {\r
-                    CmDomainDataEnum.valueOf(name);\r
-                } catch (Exception e) {\r
-                    Observation.report(LogMessages.UNDEFINED_DOMAIN_DATA_ATTRIBUTE, DomainsEnum.ChangeManagement.name(), name,\r
-                            value);\r
-                }\r
-            }\r
-        }\r
-        if (requiredFields.size() > 0) {\r
-            throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,\r
-                    requiredFields.toString());\r
-        }\r
-        return domainDataList;\r
-\r
-    }\r
-\r
-    @Override\r
-    @Transactional\r
-    public Response deleteScheduleRequest(String apiVersion, String scheduleId, HttpServletRequest request) {\r
-        Response response = null;\r
-        Observation.report(LogMessages.DELETE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId, "");\r
-        try {\r
-            Schedule schedule = scheduleDAO.findByDomainScheduleID(DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            if (schedule == null) {\r
-                throw new CMSNotFoundException(DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            }\r
-            deleteChangeManagement(schedule);\r
-            deleteScheduleRequest(DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            response = Response.noContent().build();\r
-        } catch (CMSException e) {\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-            Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-            response = Response.serverError().build();\r
-        }\r
-        Observation.report(LogMessages.DELETE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,\r
-                response.getStatusInfo().toString());\r
-        return response;\r
-    }\r
-\r
-    @Override\r
-    public Response getScheduleRequestInfo(String apiVersion, String scheduleId, HttpServletRequest request) {\r
-        Response response = null;\r
-        Observation.report(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Received", request.getRemoteAddr(), scheduleId, "");\r
-        Schedule schedule = null;\r
-        try {\r
-            schedule = scheduleDAO.findByDomainScheduleID(DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            if (schedule == null) {\r
-                throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,\r
-                        DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            }\r
-            response = Response.ok().entity(schedule).build();\r
-        } catch (CMSException e) {\r
-            Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-               Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.serverError().build();\r
-        }\r
-        Observation.report(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Returned", request.getRemoteAddr(), scheduleId,\r
-                response.getStatusInfo().toString());\r
-        return response;\r
-    }\r
-\r
-    @Override\r
-    @Transactional\r
-    public Response approveScheduleRequest(String apiVersion, String scheduleId, ApprovalMessage approval,\r
-            HttpServletRequest request) {\r
-        Response response = null;\r
-        Observation.report(LogMessages.APPROVE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,\r
-                approval.toString());\r
-        try {\r
-            String domain = DomainsEnum.ChangeManagement.toString();\r
-            Schedule s = scheduleDAO.findByDomainScheduleID(domain, scheduleId);\r
-            if (s == null) {\r
-                throw new CMSNotFoundException(domain, scheduleId);\r
-            }\r
-            processApproveScheduleRequest(s, approval, s.getDomainData());\r
-            response = Response.noContent().build();\r
-        } catch (CMSException e) {\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-            Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
-            response = Response.serverError().build();\r
-        }\r
-        Observation.report(LogMessages.APPROVE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId, "");\r
-        return response;\r
-    }\r
-\r
-    private void processApproveScheduleRequest(Schedule s, ApprovalMessage approval, List<DomainData> domainData)\r
-            throws CMSException {\r
-        s = scheduleDAO.lockOne(s.getUuid());\r
-        String domain = DomainsEnum.ChangeManagement.toString();\r
-        processApproval(s, domain, approval);\r
-        if (s.getStatus().equals(CMSStatusEnum.Accepted.toString())) {\r
-            openTickets(s, domainData);\r
-        }\r
-        if (s.getStatus().equals(CMSStatusEnum.Rejected.toString())) {\r
-            updateChangeManagementSchedules(s, CMSStatusEnum.ApprovalRejected);\r
-        }\r
-    }\r
-\r
-    private void openTickets(Schedule s, List<DomainData> domainData) throws CMSException {\r
-        debug.debug("Entered openTickets scheduleId=" + s.getScheduleId());\r
-\r
-        Integer max_vnfs_per_ticket = env.getProperty("tm.vnfs.per.ticket", Integer.class, 1);\r
-\r
-        List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getUuid());\r
-        for (ChangeManagementGroup group : groups) {\r
-\r
-            List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());\r
-            List<List<ChangeManagementSchedule>> ticketList = new ArrayList<List<ChangeManagementSchedule>>();\r
-            List<ChangeManagementSchedule> current = null;\r
-            for (ChangeManagementSchedule cms : schedules) {\r
-                if (current == null || current.size() == max_vnfs_per_ticket) {\r
-                    current = new ArrayList<ChangeManagementSchedule>();\r
-                    ticketList.add(current);\r
-                }\r
-                current.add(cms);\r
-            }\r
-            for (List<ChangeManagementSchedule> list : ticketList) {\r
-                openTicketForList(s, group, list, domainData);\r
-            }\r
-        }\r
-        debug.debug("Exited openTickets scheduleId=" + s.getScheduleId());\r
-    }\r
-\r
-    private void openTicketForList(Schedule schedule, ChangeManagementGroup group, List<ChangeManagementSchedule> list,\r
-            List<DomainData> domainData) throws CMSException {\r
-        List<String> vnfNames = new ArrayList<>();\r
-        for (ChangeManagementSchedule cms : list) {\r
-            vnfNames.add(cms.getVnfName());\r
-        }\r
-\r
-        debug.debug(\r
-                "Calling createChangeTicket scheduleId=" + schedule.getScheduleId() + ", group=" + group.getGroupId(),\r
-                ", vnfNames=" + vnfNames);\r
-        String changeId = tmClient.createChangeTicket(schedule, group, vnfNames, domainData);\r
-\r
-        // Pre-approve the ticket\r
-        for (ChangeManagementSchedule cms : list) {\r
-            cms.getTmApprovalStatus();\r
-            cms.setTmChangeId(changeId);\r
-            cms.setTmApprovalStatus(TmApprovalStatusEnum.Approved.toString());\r
-            // cms.setStatus(CMSStatusEnum.PendingApproval.toString());\r
-            if (cms.getStartTimeMillis() == null)\r
-                cms.setStatus(CMSStatusEnum.ScheduledImmediate.toString());\r
-            else\r
-                cms.setStatus(CMSStatusEnum.Scheduled.toString());\r
-            cmScheduleDAO.save(cms);\r
-        }\r
-        schedule.setStatus(CMSStatusEnum.Scheduled.toString());\r
-        scheduleDAO.save(schedule);\r
-    }\r
-\r
-    private void updateChangeManagementSchedules(Schedule s, CMSStatusEnum approvalrejected) {\r
-        debug.debug("Entered updateChangeManagementSchedules");\r
-        List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getUuid());\r
-        for (ChangeManagementGroup group : groups) {\r
-            List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());\r
-            for (ChangeManagementSchedule schedule : schedules) {\r
-                schedule.setStatus(approvalrejected.toString());\r
-                cmScheduleDAO.save(schedule);\r
-            }\r
-        }\r
-        debug.debug("Exited updateChangeManagementSchedules");\r
-    }\r
-\r
-    @Override\r
-    public Response searchScheduleRequestDetails(String apiVersion, String scheduleId, String scheduleName,\r
-            String userId, String status, String createDateTime, String optimizerStatus, String requestApprovalUserId,\r
-            String requestApprovalStatus, String requestApprovalType, String workflowName, String vnfName, String vnfId,\r
-            String vnfStatus,\r
-            // String vnfScheduleId,\r
-            String startTime, String finishTime, String lastInstanceTime, String tmChangeId,\r
-            // String approvalUserId,\r
-            // String approvalStatus,\r
-            // String approvalType,\r
-            Integer maxSchedules, String lastScheduleId, Integer concurrencyLimit, UriInfo uri,\r
-            HttpServletRequest request) {\r
-\r
-        Response response = null;\r
-        Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Received", request.getRemoteAddr(),\r
-                uri.getRequestUri().getQuery());\r
-        List<CmDetailsMessage> schedules = new ArrayList<CmDetailsMessage>();\r
-\r
-        try {\r
-            debug.debug("Timezone={}" , TimeZone.getDefault());\r
-            MultivaluedMap<String, String> qp = uri.getQueryParameters();\r
-            StringBuilder where = new StringBuilder();\r
-            int maxRows = 0;\r
-            if (maxSchedules != null && maxSchedules > 0)\r
-                maxRows = maxSchedules;\r
-            buildWhere(qp, where);\r
-            List<ChangeManagementDetail> list = cmDetailsDAO.searchScheduleDetails(where.toString(), maxRows);\r
-            if (list == null || !list.iterator().hasNext()) {\r
-                throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,\r
-                        DomainsEnum.ChangeManagement.toString(), scheduleId);\r
-            }\r
-            Iterator<ChangeManagementDetail> iter = list.iterator();\r
-            Map<UUID, Schedule> scheduleMap = new HashMap<UUID, Schedule>();\r
-            while (iter.hasNext()) {\r
-                ChangeManagementDetail cms = iter.next();\r
-                CmDetailsMessage msg = buildResponse(cms, scheduleMap);\r
-                schedules.add(msg);\r
-            }\r
-            response = Response.ok(schedules.toArray(new CmDetailsMessage[schedules.size()])).build();\r
-        } catch (CMSException e) {\r
-            Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
-            response = Response.serverError().build();\r
-        }\r
-        Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Returned", request.getRemoteAddr(),\r
-                response.getStatusInfo().toString());\r
-        return response;\r
-\r
-    }\r
-\r
-    private void buildWhere(MultivaluedMap<String, String> qp, StringBuilder where) throws CMSException {\r
-        String delim = " where ";\r
-        for (String urlName : qp.keySet()) {\r
-            List<String> values = qp.get(urlName);\r
-            String clause = CmQueryParameters.buildClause(urlName, values);\r
-            if (clause != null && !clause.equals("")) {\r
-                where.append(delim).append("\n").append(clause).append("\n");\r
-                delim = "AND";\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    private CmDetailsMessage buildResponse(ChangeManagementDetail cms, Map<UUID, Schedule> scheduleMap) {\r
-        CmDetailsMessage msg = new CmDetailsMessage();\r
-        msg.setVnfId(cms.getVnfId());\r
-        msg.setVnfName(cms.getVnfName());\r
-        msg.setStatus(cms.getStatus());\r
-        msg.setTmChangeId(cms.getTmChangeId());\r
-        msg.setFinishTimeMillis(cms.getFinishTimeMillis());\r
-        msg.setStartTimeMillis(cms.getStartTimeMillis());\r
-        msg.setLastInstanceStartTimeMillis(cms.getLastInstanceStartTimeMillis());\r
-        msg.setGroupId(cms.getGroupId());\r
-        msg.setPolicyId(cms.getPolicyId());\r
-        msg.setTmApprovalStatus(cms.getTmApprovalStatus());\r
-        msg.setTmStatus(cms.getTmStatus());\r
-        msg.setStatusMessage(cms.getStatusMessage());\r
-        msg.setDispatchTimeMillis(cms.getDispatchTimeMillis());\r
-        msg.setExecutionCompletedTimeMillis(cms.getExecutionCompletedTimeMillis());\r
-        msg.setMsoMessage(cms.getMsoMessage());\r
-        msg.setMsoRequestId(cms.getMsoRequestId());\r
-        msg.setMsoStatus(cms.getMsoStatus());\r
-        msg.setMsoTimeMillis(cms.getMsoTimeMillis());\r
-        if (!scheduleMap.containsKey(cms.getSchedulesUuid())) {\r
-            Schedule schedule = scheduleDAO.findById(cms.getSchedulesUuid()).orElse(null);\r
-            if (schedule != null) {\r
-                // DO not innclude in the results\r
-                schedule.setScheduleInfo(null);\r
-                // schedule.setSchedule(null);\r
-                scheduleMap.put(cms.getSchedulesUuid(), schedule);\r
-            }\r
-        }\r
-        if (scheduleMap.containsKey(cms.getSchedulesUuid())) {\r
-            msg.setScheduleRequest(scheduleMap.get(cms.getSchedulesUuid()));\r
-        }\r
-        return msg;\r
-    }\r
-\r
-}\r
index 9877d33..2e9ade3 100644 (file)
@@ -1,33 +1,28 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.service.rs;\r
 \r
@@ -41,182 +36,213 @@ import org.onap.optf.cmso.common.LogMessages;
 import org.onap.optf.cmso.common.exceptions.CMSException;\r
 import org.onap.optf.cmso.model.DomainData;\r
 \r
+/**\r
+ * The Class CmQueryParameters.\r
+ */\r
 public class CmQueryParameters {\r
 \r
-       public enum QueryColumns {\r
-               RequestScheduleId("request.scheduleId", String.class, "ss.schedule_id"),\r
-               RequestScheduleName("request.scheduleName", String.class, "ss.schedule_name"),\r
-               RequestUserId("request.userId", String.class, "ss.user_id"),\r
-               RequestStatus("request.status", String.class, "ss.status"),\r
-               RequestCreateDateTime("request.createDateTime", Date.class, "ss.create_date_time"),\r
-               RequestOptimizerStatus("request.optimizerStatus", String.class, "ss.optimizer_status"),\r
-               RequestApprovalUserId("request.approvalUserId", String.class, "sa.user_id"),\r
-               RequestApprovalStatus("request.approvalStatus", String.class, "sa.status"),\r
-               RequestApprovalType("request.approvalType", String.class, "at.approval_type"),\r
-               WorkflowName("WorkflowName", DomainData.class, "dd.value"), vnfName("vnfName", String.class, "s.vnf_name"),\r
-               vnfId("vnfId", String.class, "s.vnf_id"), vnfStatus("vnfStatus", String.class, "s.vnf_status"),\r
-               // vnfScheduleId("vnfScheduleId", String.class, "s.id"),\r
-               startTime("startTime", Date.class, "s.start_time"), finishTime("finishTime", Date.class, "s.finish_ime"),\r
-               lastInstanceTime("lastInstanceTime", Date.class, "g.last_instance_time"),\r
-               tmChangeId("tmChangeId", String.class, "s.tm_change_id"),\r
-               concurrenyLimit("request.concurrencyLimit", Integer.class, "g.concurrency_limit"),\r
-               // approvalUserId("approvalUserId", String.class, "approvalUserId"),\r
-               // approvalStatus("approvalStatus", String.class, "approvalStatus"),\r
-               // approvalType("approvalType", String.class, "approvalType"),\r
-               ;\r
+    /**\r
+     * The Enum QueryColumns.\r
+     */\r
+    public enum QueryColumns {\r
+        RequestScheduleId("request.scheduleId", String.class, "ss.schedule_id"),\r
+        RequestScheduleName("request.scheduleName", String.class, "ss.schedule_name"),\r
+        RequestUserId("request.userId", String.class, "ss.user_id"),\r
+        RequestStatus("request.status", String.class, "ss.status"),\r
+        RequestCreateDateTime("request.createDateTime", Date.class, "ss.create_date_time"),\r
+        RequestOptimizerStatus("request.optimizerStatus", String.class, "ss.optimizer_status"),\r
+        RequestApprovalUserId("request.approvalUserId", String.class, "sa.user_id"),\r
+        RequestApprovalStatus("request.approvalStatus", String.class, "sa.status"),\r
+        RequestApprovalType("request.approvalType", String.class, "at.approval_type"),\r
+        WorkflowName("WorkflowName", DomainData.class, "dd.value"),\r
+        vnfName("vnfName", String.class, "s.vnf_name"),\r
+        vnfId("vnfId", String.class, "s.vnf_id"),\r
+        vnfStatus("vnfStatus", String.class, "s.vnf_status"),\r
+        // vnfScheduleId("vnfScheduleId", String.class, "s.id"),\r
+        startTime("startTime", Date.class, "s.start_time"),\r
+        finishTime("finishTime", Date.class, "s.finish_ime"),\r
+        lastInstanceTime("lastInstanceTime", Date.class, "g.last_instance_time"),\r
+        tmChangeId("tmChangeId", String.class, "s.tm_change_id"),\r
+        concurrenyLimit("request.concurrencyLimit", Integer.class, "g.concurrency_limit"),\r
+        // approvalUserId("approvalUserId", String.class, "approvalUserId"),\r
+        // approvalStatus("approvalStatus", String.class, "approvalStatus"),\r
+        // approvalType("approvalType", String.class, "approvalType"),\r
+        ;\r
 \r
-               private final String urlName;\r
-               private final Class<?> type;\r
-               private final String col;\r
+        private final String urlName;\r
+        private final Class<?> type;\r
+        private final String col;\r
 \r
-               private QueryColumns(String urlName, Class<?> type, String col) {\r
-                       this.urlName = urlName;\r
-                       this.type = type;\r
-                       this.col = col;\r
-               }\r
+        private QueryColumns(String urlName, Class<?> type, String col) {\r
+            this.urlName = urlName;\r
+            this.type    = type;\r
+            this.col     = col;\r
+        }\r
 \r
-       }\r
+    }\r
 \r
-       public static QueryColumns getQueryColumn(String urlName) {\r
-               for (QueryColumns qc : QueryColumns.values()) {\r
-                       if (qc.urlName.equals(urlName))\r
-                               return qc;\r
-               }\r
-               return null;\r
-       }\r
+    /**\r
+     * Gets the query column.\r
+     *\r
+     * @param urlName the url name\r
+     * @return the query column\r
+     */\r
+    public static QueryColumns getQueryColumn(String urlName) {\r
+        for (QueryColumns qc : QueryColumns.values()) {\r
+            if (qc.urlName.equals(urlName)) {\r
+                return qc;\r
+            }\r
+        }\r
+        return null;\r
+    }\r
 \r
-       public static String buildClause(String urlName, List<String> values) throws CMSException {\r
-               QueryColumns qc = getQueryColumn(urlName);\r
-               if (qc == null) {\r
-                       throw new CMSException(Status.BAD_REQUEST, LogMessages.UNDEFINED_FILTER_ATTRIBUTE, urlName);\r
-               }\r
-               if (qc.type == Date.class) {\r
-                       return formatDate(urlName, values, qc);\r
-               }\r
-               if (qc.type == DomainData.class) {\r
-                       return formatDomainData(urlName, values, qc);\r
-               }\r
-               return formatString(urlName, values, qc);\r
-       }\r
+    /**\r
+     * Builds the clause.\r
+     *\r
+     * @param urlName the url name\r
+     * @param values the values\r
+     * @return the string\r
+     * @throws CMSException the CMS exception\r
+     */\r
+    public static String buildClause(String urlName, List<String> values) throws CMSException {\r
+        QueryColumns qc = getQueryColumn(urlName);\r
+        if (qc == null) {\r
+            throw new CMSException(Status.BAD_REQUEST, LogMessages.UNDEFINED_FILTER_ATTRIBUTE, urlName);\r
+        }\r
+        if (qc.type == Date.class) {\r
+            return formatDate(urlName, values, qc);\r
+        }\r
+        if (qc.type == DomainData.class) {\r
+            return formatDomainData(urlName, values, qc);\r
+        }\r
+        return formatString(urlName, values, qc);\r
+    }\r
 \r
-       private static String formatString(String urlName, List<String> values, QueryColumns qc) {\r
-               StringBuilder clause = new StringBuilder();\r
-               List<String> likes = new ArrayList<String>();\r
-               List<String> in = new ArrayList<String>();\r
-               for (String value : values) {\r
-                       if (value.contains("%"))\r
-                               likes.add(value);\r
-                       else\r
-                               in.add(value);\r
-               }\r
-               String delim = "(";\r
-               if (in.size() > 0) {\r
-                       clause.append(delim).append(qc.col).append(" in ('");\r
-                       String inDelim = "";\r
-                       for (String value : in) {\r
-                               clause.append(inDelim).append(value).append("'");\r
-                               inDelim = ", '";\r
-                       }\r
-                       clause.append(") ");\r
-                       delim = " OR ";\r
-               }\r
-               if (likes.size() > 0) {\r
-                       for (String value : likes) {\r
-                               clause.append(delim).append(qc.col).append(" like '").append(value).append("'");\r
-                               delim = " OR ";\r
-                       }\r
-               }\r
-               if (!delim.equals("("))\r
-                       clause.append(")");\r
-               return clause.toString();\r
-       }\r
+    private static String formatString(String urlName, List<String> values, QueryColumns qc) {\r
+        StringBuilder clause = new StringBuilder();\r
+        List<String> likes = new ArrayList<String>();\r
+        List<String> in = new ArrayList<String>();\r
+        for (String value : values) {\r
+            if (value.contains("%")) {\r
+                likes.add(value);\r
+            }\r
+            else {\r
+                in.add(value);\r
+            }\r
+        }\r
+        String delim = "(";\r
+        if (in.size() > 0) {\r
+            clause.append(delim).append(qc.col).append(" in ('");\r
+            String inDelim = "";\r
+            for (String value : in) {\r
+                clause.append(inDelim).append(value).append("'");\r
+                inDelim = ", '";\r
+            }\r
+            clause.append(") ");\r
+            delim = " OR ";\r
+        }\r
+        if (likes.size() > 0) {\r
+            for (String value : likes) {\r
+                clause.append(delim).append(qc.col).append(" like '").append(value).append("'");\r
+                delim = " OR ";\r
+            }\r
+        }\r
+        if (!delim.equals("(")) {\r
+            clause.append(")");\r
+        }\r
+        return clause.toString();\r
+    }\r
 \r
-       private static String formatDomainData(String urlName, List<String> values, QueryColumns qc) {\r
-               StringBuilder clause = new StringBuilder();\r
-               String delim = "(";\r
-               if (values.size() > 0) {\r
-                       for (String value : values) {\r
-                               clause.append(delim).append(" (dd.name = '").append(qc.urlName).append("' AND dd.value = '")\r
-                                               .append(value).append("')");\r
-                               delim = " OR ";\r
-                       }\r
-               }\r
-               if (!delim.equals("("))\r
-                       clause.append(")");\r
-               return clause.toString();\r
-       }\r
+    private static String formatDomainData(String urlName, List<String> values, QueryColumns qc) {\r
+        StringBuilder clause = new StringBuilder();\r
+        String delim = "(";\r
+        if (values.size() > 0) {\r
+            for (String value : values) {\r
+                clause.append(delim).append(" (dd.name = '").append(qc.urlName).append("' AND dd.value = '")\r
+                                .append(value).append("')");\r
+                delim = " OR ";\r
+            }\r
+        }\r
+        if (!delim.equals("(")) {\r
+            clause.append(")");\r
+        }\r
+        return clause.toString();\r
+    }\r
 \r
-       private static String formatDate(String urlName, List<String> values, QueryColumns qc) throws CMSException {\r
-               List<String> clauses = new ArrayList<String>();\r
-               for (String value : values) {\r
-                       String dates[] = value.split(",");\r
-                       switch (dates.length) {\r
-                       case 2:\r
-                               formatDatePair(qc, dates[0].trim(), dates[1].trim(), clauses);\r
-                               break;\r
-                       case 1:\r
-                               formatDatePair(qc, dates[0].trim(), "", clauses);\r
-                               break;\r
-                       default:\r
-                               throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, value);\r
-                       }\r
-               }\r
-               StringBuilder clause = new StringBuilder();\r
-               String delim = "(";\r
-               for (String c : clauses) {\r
-                       clause.append(delim).append(c);\r
-                       delim = " OR ";\r
-               }\r
-               if (!delim.equals(")")) {\r
-                       clause.append(")");\r
-               }\r
-               return clause.toString();\r
-       }\r
+    private static String formatDate(String urlName, List<String> values, QueryColumns qc) throws CMSException {\r
+        List<String> clauses = new ArrayList<String>();\r
+        for (String value : values) {\r
+            String[] dates = value.split(",");\r
+            switch (dates.length) {\r
+                case 2:\r
+                    formatDatePair(qc, dates[0].trim(), dates[1].trim(), clauses);\r
+                    break;\r
+                case 1:\r
+                    formatDatePair(qc, dates[0].trim(), "", clauses);\r
+                    break;\r
+                default:\r
+                    throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, value);\r
+            }\r
+        }\r
+        StringBuilder clause = new StringBuilder();\r
+        String delim = "(";\r
+        for (String c : clauses) {\r
+            clause.append(delim).append(c);\r
+            delim = " OR ";\r
+        }\r
+        if (!delim.equals(")")) {\r
+            clause.append(")");\r
+        }\r
+        return clause.toString();\r
+    }\r
 \r
-       private static void formatDatePair(QueryColumns qc, String lowDate, String highDate, List<String> clauses)\r
-                       throws CMSException {\r
-               StringBuilder clause = new StringBuilder();\r
-               DateTime date1 = null;\r
-               DateTime date2 = null;\r
-               if (!lowDate.equals(""))\r
-                       date1 = convertDate(lowDate, qc.urlName);\r
-               if (!highDate.equals(""))\r
-                       date2 = convertDate(highDate, qc.urlName);\r
-               String delim = "(";\r
-               if (date1 != null) {\r
-                       clause.append(delim).append(qc.col).append(" >= ").append(date1.getMillis());\r
-                       delim = " AND ";\r
-               }\r
-               if (date2 != null) {\r
-                       clause.append(delim).append(qc.col).append(" <= ").append(date2.getMillis());\r
-                       delim = " AND ";\r
-               }\r
-               if (!delim.equals(")")) {\r
-                       clause.append(")\n");\r
-                       clauses.add(clause.toString());\r
-               }\r
-       }\r
+    private static void formatDatePair(QueryColumns qc, String lowDate, String highDate, List<String> clauses)\r
+                    throws CMSException {\r
+        StringBuilder clause = new StringBuilder();\r
+        DateTime date1 = null;\r
+        DateTime date2 = null;\r
+        if (!lowDate.equals("")) {\r
+            date1 = convertDate(lowDate, qc.urlName);\r
+        }\r
+        if (!highDate.equals("")) {\r
+            date2 = convertDate(highDate, qc.urlName);\r
+        }\r
+        String delim = "(";\r
+        if (date1 != null) {\r
+            clause.append(delim).append(qc.col).append(" >= ").append(date1.getMillis());\r
+            delim = " AND ";\r
+        }\r
+        if (date2 != null) {\r
+            clause.append(delim).append(qc.col).append(" <= ").append(date2.getMillis());\r
+            delim = " AND ";\r
+        }\r
+        if (!delim.equals(")")) {\r
+            clause.append(")\n");\r
+            clauses.add(clause.toString());\r
+        }\r
+    }\r
 \r
-       private static DateTime convertDate(String utcDate, String urlName) throws CMSException {\r
-               DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate);\r
-               if (dateTime != null)\r
-                       return dateTime;\r
-               throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, utcDate);\r
-       }\r
+    private static DateTime convertDate(String utcDate, String urlName) throws CMSException {\r
+        DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate);\r
+        if (dateTime != null) {\r
+            return dateTime;\r
+        }\r
+        throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, utcDate);\r
+    }\r
 \r
-       // public static void main(String argv[])\r
-       // {\r
-       // List<String> values = new ArrayList<String>();\r
-       // values.add("2017-07-08T11:12:13Z,2017-07-08T11:12:13Z");\r
-       // values.add("2017-07-09T11:12:13Z,2017-07-09T11:12:13Z");\r
-       // values.add(",2017-07-09T11:12:13Z");\r
-       // values.add(" 2017-07-09T11:12:13Z");\r
-       // try {\r
-       // System.out.println(buildClause("request.createDateTime", values));\r
-       // } catch (SchedulerException e) {\r
-       // // TODO Auto-generated catch block\r
-       // e.printStackTrace();\r
-       // }\r
-       //\r
-       // }\r
+    // public static void main(String argv[])\r
+    // {\r
+    // List<String> values = new ArrayList<String>();\r
+    // values.add("2017-07-08T11:12:13Z,2017-07-08T11:12:13Z");\r
+    // values.add("2017-07-09T11:12:13Z,2017-07-09T11:12:13Z");\r
+    // values.add(",2017-07-09T11:12:13Z");\r
+    // values.add(" 2017-07-09T11:12:13Z");\r
+    // try {\r
+    // System.out.println(buildClause("request.createDateTime", values));\r
+    // } catch (SchedulerException e) {\r
+    // // TODO Auto-generated catch block\r
+    // e.printStackTrace();\r
+    // }\r
+    //\r
+    // }\r
 }\r
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java
new file mode 100644 (file)
index 0000000..9874ea8
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.service.rs;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.optf.cmso.common.CMSRequestError;
+import org.onap.optf.cmso.service.rs.models.v2.OptimizedScheduleMessage;
+
+@Api("CMSO Optimized Schedule API")
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CmsoOptimizedScheduleService {
+
+    // ******************************************************************
+    @POST
+    @Path("/schedules/optimized/{scheduleId}")
+    @Produces({MediaType.APPLICATION_JSON})
+    @ApiOperation(value = "", notes = "Creates a request for an optimized schedule")
+    @ApiResponses(
+            value = {@ApiResponse(code = 202, message = "Schedule request accepted for optimization."),
+                    @ApiResponse(code = 409, message = "Schedule request already exists for this schedule id.",
+                            response = CMSRequestError.class),
+                    @ApiResponse(code = 500, message = "Unexpected Runtime error")})
+    public Response createScheduleRequest(
+            @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+            @ApiParam(value = "Schedule id to uniquely identify the schedule request being created.")
+            @PathParam("scheduleId") String scheduleId,
+            @ApiParam(value = "Data for creating a schedule request for the given schedule id")
+            OptimizedScheduleMessage scheduleMessage);
+
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java
new file mode 100644 (file)
index 0000000..377c250
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation 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.
+ */
+
+package org.onap.optf.cmso.service.rs;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.service.rs.models.v2.OptimizedScheduleMessage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+@Controller
+public class CmsoOptimizedScheduleServiceImpl extends CommonServiceImpl implements CmsoOptimizedScheduleService {
+    private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+
+    @Autowired
+    Environment env;
+
+
+    @Context
+    HttpServletRequest request;
+
+    @Override
+    @Transactional
+    public Response createScheduleRequest(String apiVersion, String scheduleId,
+                    OptimizedScheduleMessage scheduleMessage) {
+        Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,
+                        scheduleMessage.toString());
+        Response response = null;
+        try {
+            createSchedule(scheduleMessage, scheduleId, request);
+            response = Response.accepted().build();
+        } catch (CMSException e) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
+            response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+        } catch (Exception e) {
+            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            response = Response.serverError().build();
+        }
+        Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+                        response.getStatusInfo().toString());
+        return response;
+    }
+
+
+}
@@ -1,66 +1,64 @@
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
-\r
-package org.onap.optf.cmso.service.rs;\r
-\r
-import javax.ws.rs.DefaultValue;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
-\r
-import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;\r
-\r
-import io.swagger.annotations.Api;\r
-import io.swagger.annotations.ApiOperation;\r
-import io.swagger.annotations.ApiParam;\r
-import io.swagger.annotations.ApiResponse;\r
-import io.swagger.annotations.ApiResponses;\r
-\r
-@Api("CMSO Optimized Schedule API")\r
-@Path("/{apiVersion}")\r
-@Produces({MediaType.APPLICATION_JSON})\r
-public interface CMSOptimizerCallback {\r
-\r
-    // ******************************************************************\r
-    @POST\r
-    @Path("/optimizerCallback")\r
-    @Produces({MediaType.APPLICATION_JSON})\r
-    @ApiOperation(value = "", notes = "Processes optimizer results callback to a Pending Optimization schedule.")\r
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),\r
-            @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})\r
-    public Response sniroCallback(\r
-            @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,\r
-            @ApiParam(value = "Return schedules > lastScheduleId") CMOptimizerResponse reponse);\r
-\r
-}\r
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ * 
+ * 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.
+ * 
+ * 
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *         https://creativecommons.org/licenses/by/4.0/
+ * 
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.service.rs;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
+
+@Api("CMSO Optimized Schedule API")
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CmsoOptimizerCallback {
+
+    // ******************************************************************
+    @POST
+    @Path("/optimizerCallback")
+    @Produces({MediaType.APPLICATION_JSON})
+    @ApiOperation(value = "", notes = "Processes optimizer results callback to a Pending Optimization schedule.")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
+            @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
+    public Response sniroCallback(
+            @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+            @ApiParam(value = "Return schedules > lastScheduleId") CMOptimizerResponse reponse);
+
+}