aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-01-15 18:56:23 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-01-16 11:56:32 +0000
commitc3f68a3a585985d394116e8c8f141b77619793e1 (patch)
treee73bf909b2c260bfba84f452f074225b85910f91
parent5226d07347890d68463dfce0288ccfc5e3acaba6 (diff)
Removed MDC from four modules
Change-Id: I4cba1701cb52121709bbd98dbee4a0cb42f1e5f0 Issue-ID: SDC-772 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml2
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java28
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java36
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml31
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java66
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml1
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java116
9 files changed, 86 insertions, 226 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
index 5d9b49892f..da8147f287 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
@@ -16,8 +16,8 @@
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-logging-core</artifactId>
<version>${project.version}</version>
+ <scope>runtime</scope>
</dependency>
-
<dependency>
<groupId>org.openecomp.sdc.core</groupId>
<artifactId>openecomp-utilities-lib</artifactId>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java
index 8ae3d30846..8b6fca5ae1 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java
@@ -17,12 +17,7 @@
package org.openecomp.sdcrests.mapping;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.datatypes.error.ErrorLevel;
-import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
-import org.openecomp.sdc.logging.types.LoggerConstants;
-import org.openecomp.sdc.logging.types.LoggerServiceName;
/**
* Base class for all mapping classes. Mapping classes will perform data mapping from source object
@@ -62,8 +57,8 @@ public abstract class MappingBase<S, T> {
/**
* This method is called before the <code>doMapping</code> method.
*/
-
public void preMapping(final S source, T target) {
+ // extension point
}
/**
@@ -80,8 +75,8 @@ public abstract class MappingBase<S, T> {
/**
* This method is called after the <code>doMapping</code> method.
*/
-
public void postMapping(final S source, T target) {
+ // extension point
}
/**
@@ -91,26 +86,13 @@ public abstract class MappingBase<S, T> {
*/
private Object instantiateTarget(final Class<?> clazz) {
- Object object = null;
- try {
- object = clazz.newInstance();
+ try {
+ return clazz.newInstance();
} catch (InstantiationException | IllegalAccessException exception ) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(
- LoggerConstants.TARGET_ENTITY,
- LoggerServiceName.Create_LIMIT.toString(), ErrorLevel.ERROR.name(),
- exception.getMessage(), exception.getMessage());
-
throw new CoreException((new ErrorCode.ErrorCodeBuilder())
- .withMessage(exception.getMessage())
- .withId(exception.getMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
-
-
+ .withMessage(exception.getMessage()).build(), exception);
}
- return object;
-
}
-
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
index e6c72d1694..d90c9a39a0 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
@@ -60,6 +60,7 @@
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-logging-core</artifactId>
<version>${project.version}</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.openecomp.sdc</groupId>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
index e05d02d1e7..7525a6479a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
@@ -39,15 +39,9 @@ import com.amdocs.zusammen.datatypes.item.Resolution;
import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
import com.amdocs.zusammen.datatypes.response.Response;
-import com.amdocs.zusammen.datatypes.response.ReturnCode;
import org.openecomp.core.zusammen.db.ZusammenConnector;
import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
-import org.openecomp.core.zusammen.impl.ItemElementLoggerTargetServiceName;
import org.openecomp.sdc.common.errors.SdcRuntimeException;
-import org.openecomp.sdc.datatypes.error.ErrorLevel;
-import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
-import org.openecomp.sdc.logging.types.LoggerConstants;
-import org.openecomp.sdc.logging.types.LoggerErrorCode;
import java.util.Collection;
@@ -57,10 +51,10 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
"Failed to get element. Item Id: %s, version Id: %s, element Id: %s message: %s";
private static final String GET_ELEMENT_IN_REV_ERR_MSG =
"Failed to get element. Item Id: %s, version Id: %s, revision Id: %s, element Id: %s message: %s";
- private ItemAdaptorFactory itemAdaptorFactory;
- private ItemVersionAdaptorFactory versionAdaptorFactory;
- private ElementAdaptorFactory elementAdaptorFactory;
- private HealthAdaptorFactory healthAdaptorFactory;
+ private final ItemAdaptorFactory itemAdaptorFactory;
+ private final ItemVersionAdaptorFactory versionAdaptorFactory;
+ private final ElementAdaptorFactory elementAdaptorFactory;
+ private final HealthAdaptorFactory healthAdaptorFactory;
public ZusammenConnectorImpl(
ItemAdaptorFactory itemAdaptorFactory,
@@ -130,8 +124,6 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
Response<Collection<ItemVersion>> versions =
versionAdaptorFactory.createInterface(context).list(context, Space.PUBLIC, itemId);
if (!versions.isSuccessful()) {
- logErrorMessageToMdc(ItemElementLoggerTargetServiceName.ITEM_VERSION_RETRIEVAL, versions
- .getReturnCode());
throw new SdcRuntimeException("failed to list public versions. message: " +
versions.getReturnCode().toString());
}
@@ -309,8 +301,6 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
if (response.isSuccessful()) {
return response.getValue();
} else {
- logErrorMessageToMdc(ItemElementLoggerTargetServiceName.ELEMENT_GET_BY_PROPERTY,
- response.getReturnCode());
throw new SdcRuntimeException(response.getReturnCode().toString());
}
}
@@ -399,22 +389,4 @@ public class ZusammenConnectorImpl implements ZusammenConnector {
elementContext.getRevisionId().getValue(),
elementId.getValue(), zusammenErrorMessage));
}
-
- private void logErrorMessageToMdc(ItemElementLoggerTargetServiceName
- itemElementLoggerTargetServiceName,
- ReturnCode returnCode) {
- logErrorMessageToMdc(itemElementLoggerTargetServiceName, returnCode.toString());
- }
-
- private void logErrorMessageToMdc(ItemElementLoggerTargetServiceName
- itemElementLoggerTargetServiceName,
- String message) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- itemElementLoggerTargetServiceName.getDescription(),
- ErrorLevel.ERROR.name(),
- LoggerErrorCode.BUSINESS_PROCESS_ERROR.getErrorCode(),
- message);
- }
-
-
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml
index a420b23f6e..60c8cd08f9 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml
@@ -17,31 +17,30 @@
<dependencies>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet-api.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.openecomp.sdc.core</groupId>
<artifactId>openecomp-session-lib</artifactId>
<version>${project.version}</version>
</dependency>
-
-
<dependency>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-item-permissions-api</artifactId>
<version>${project.version}</version>
</dependency>
-
-
<dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-facade-core</artifactId>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-facade-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-nosqldb-core</artifactId>
<version>${project.version}</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-nosqldb-core</artifactId>
- <version>${project.version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-notification-api</artifactId>
@@ -50,12 +49,12 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
- <version>RELEASE</version>
+ <version>${mockito.all.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <version>RELEASE</version>
+ <version>${testng.version}</version>
</dependency>
</dependencies>
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
index 21acc07733..4a8f44657e 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.
+ */
+
package org.openecomp.sdc.itempermissions.servlet;
import org.openecomp.sdc.itempermissions.PermissionsServices;
@@ -19,43 +35,51 @@ import java.io.IOException;
public class PermissionsFilter implements Filter {
private final PermissionsServices permissionsServices;
- public static final String IRRELEVANT_REQUEST = "Irrelevant_Request";
- public static final String EDIT_ITEM = "Edit_Item";
+ private static final String IRRELEVANT_REQUEST = "Irrelevant_Request";
+ private static final String EDIT_ITEM = "Edit_Item";
public PermissionsFilter() {
this.permissionsServices = PermissionsServicesFactory.getInstance().createInterface();
}
@Override
- public void init(FilterConfig filterConfig) throws ServletException {
-
+ public void init(FilterConfig filterConfig) {
+ // required by servlet API
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
- if (servletRequest instanceof HttpServletRequest) {
- if (((HttpServletRequest) servletRequest).getMethod().equals("POST")
- || ((HttpServletRequest) servletRequest).getMethod().equals("PUT")) {
-
- String userId = ((HttpServletRequest) servletRequest).getHeader("USER_ID");
- String itemId = parseItemIdFromPath(((HttpServletRequest) servletRequest).getPathInfo());
- if ( ! itemId.equals(IRRELEVANT_REQUEST)) {
- if ( ! permissionsServices.isAllowed(itemId,userId,EDIT_ITEM)) {
- ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN);
- servletResponse.getWriter().print("Permissions Error. The user does not have " +
- "permission to perform" +
- " this action.");
- return;
- }
- }
- }
+ if ((servletRequest instanceof HttpServletRequest) &&
+ isIrrelevant((HttpServletRequest) servletRequest, servletResponse)) {
+ return;
}
filterChain.doFilter(servletRequest, servletResponse);
}
+ private boolean isIrrelevant(HttpServletRequest servletRequest, ServletResponse servletResponse) throws IOException {
+
+
+ String method = servletRequest.getMethod();
+ if (method.equals("POST") || method.equals("PUT")) {
+
+ String userId = servletRequest.getHeader("USER_ID");
+ String itemId = parseItemIdFromPath(servletRequest.getPathInfo());
+
+ if (!itemId.equals(IRRELEVANT_REQUEST) && !permissionsServices.isAllowed(itemId,userId,EDIT_ITEM)) {
+ ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ servletResponse.getWriter().print("Permissions Error. The user does not have " +
+ "permission to perform" +
+ " this action.");
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private String parseItemIdFromPath(String pathInfo) {
String[] tokens = pathInfo.split("/");
if (tokens.length < 4) {
@@ -67,6 +91,6 @@ public class PermissionsFilter implements Filter {
@Override
public void destroy() {
-
+ // required by serlvet API
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java
deleted file mode 100644
index f78fd7094b..0000000000
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.logging.util;
-
-/**
- * Created by TALIO on 1/10/2017.
- */
-public class LoggingUtils {
-
- public static String getCallingMethodNameForDebugging() {
- return Thread.currentThread().getStackTrace()[4].getMethodName();
- }
-
- public static String getDeclaringClass(){
- return Thread.currentThread().getStackTrace()[4].getClassName();
- }
-}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
index 2bcb0551d5..951357bfd6 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
@@ -59,6 +59,7 @@
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-logging-core</artifactId>
<version>${project.version}</version>
+ <scope>runtime</scope>
</dependency>
</dependencies>
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 18baebfcae..af63d86b69 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -1,36 +1,25 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
-import org.openecomp.sdc.logging.types.LoggerConstants;
-import org.openecomp.sdc.logging.types.LoggerErrorCode;
-import org.openecomp.sdc.logging.types.LoggerErrorDescription;
-import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
import org.openecomp.sdc.versioning.ItemManager;
import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.VersioningManager;
@@ -61,7 +50,6 @@ import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
-import org.slf4j.MDC;
import java.util.Collection;
import java.util.HashMap;
@@ -133,17 +121,11 @@ public class VersioningManagerImpl implements VersioningManager {
if (user.equals(candidate.getUser())) {
activeVersion = candidate.getVersion();
} else {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(
new EditOnEntityLockedByOtherErrorBuilder(entityType, entityId, candidate.getUser())
.build());
}
} else {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(new EditOnUnlockedEntityErrorBuilder(entityType, entityId).build());
}
} else {
@@ -180,8 +162,8 @@ public class VersioningManagerImpl implements VersioningManager {
private static List<Version> toSortedList(
Set<Version> versions) { // changing the Set to List in DB will require migration...
return versions.stream().sorted((o1, o2) -> o1.getMajor() > o2.getMajor() ? 1
- : o1.getMajor() == o2.getMajor() ? (o1.getMinor() > o2.getMinor() ? 1
- : o1.getMinor() == o2.getMinor() ? 0 : -1) : -1).collect(Collectors.toList());
+ : o1.getMajor() == o2.getMajor() ? (Integer.compare(o1.getMinor(), o2.getMinor())) : -1)
+ .collect(Collectors.toList());
}
private static List<Version> getFinalVersions(Set<Version> versions) {
@@ -200,9 +182,6 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity
versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity != null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.CREATE_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't create versionable entity");
throw new CoreException(new EntityAlreadyExistErrorBuilder(entityType, entityId).build());
}
@@ -219,22 +198,12 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't delete versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
- switch (versionInfoEntity.getStatus()) {
- case Locked:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't delete versionable entity");
- throw new CoreException(new DeleteOnLockedEntityErrorBuilder(entityType, entityId,
- versionInfoEntity.getCandidate().getUser()).build());
- default:
- //do nothing
- break;
+ if (versionInfoEntity.getStatus() == VersionStatus.Locked) {
+ throw new CoreException(new DeleteOnLockedEntityErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
}
doDelete(versionInfoEntity);
@@ -245,9 +214,6 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoDeletedEntity versionInfoDeletedEntity =
versionInfoDeletedDao.get(new VersionInfoDeletedEntity(entityType, entityId));
if (versionInfoDeletedEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.UNDO_DELETE_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't undo delete for versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
@@ -258,20 +224,13 @@ public class VersioningManagerImpl implements VersioningManager {
public Version checkout(String entityType, String entityId, String user) {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
- MDC.put(LoggerConstants.TARGET_SERVICE_NAME, LoggerTragetServiceName.CHECKOUT_ENTITY);
if (versionInfoEntity == null) {
- MDC.put(LoggerConstants.ERROR_CATEGORY, ErrorLevel.ERROR.name());
- MDC.put(LoggerConstants.TARGET_ENTITY, LoggerConstants.TARGET_ENTITY_DB);
- MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.CHECKOUT_ENTITY);
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
Version checkoutVersion = null;
switch (versionInfoEntity.getStatus()) {
case Locked:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkout versionable entity");
throw new CoreException(new CheckoutOnLockedEntityErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
case Certified:
@@ -291,9 +250,6 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't undo checkout for versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
@@ -301,10 +257,6 @@ public class VersioningManagerImpl implements VersioningManager {
switch (versionInfoEntity.getStatus()) {
case Locked:
if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(),
- "Can't undo checkout for versionable entity");
throw new CoreException(
new UndoCheckoutOnEntityLockedByOtherErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
@@ -313,10 +265,6 @@ public class VersioningManagerImpl implements VersioningManager {
break;
case Certified:
case Draft:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(),
- "Can't undo checkout for versionable entity");
throw new CoreException(
new UndoCheckoutOnUnlockedEntityErrorBuilder(entityType, entityId).build());
default:
@@ -345,9 +293,6 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
@@ -355,20 +300,14 @@ public class VersioningManagerImpl implements VersioningManager {
switch (versionInfoEntity.getStatus()) {
case Draft:
case Certified:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(
new CheckinOnUnlockedEntityErrorBuilder(entityType, entityId).build());
case Locked:
if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(new CheckinOnEntityLockedByOtherErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
}
- checkedInVersion = doCheckin(versionInfoEntity, checkinDescription);
+ checkedInVersion = doCheckin(versionInfoEntity);
break;
default:
//do nothing
@@ -383,28 +322,19 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
Version submitVersion = null;
switch (versionInfoEntity.getStatus()) {
case Certified:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(
new EntityAlreadyFinalizedErrorBuilder(entityType, entityId).build());
case Locked:
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
case Draft:
- submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
+ submitVersion = doSubmit(versionInfoEntity);
break;
default:
//do nothing
@@ -420,9 +350,6 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
return getVersionInfo(versionInfoEntity, user, action);
@@ -521,14 +448,7 @@ public class VersioningManagerImpl implements VersioningManager {
String errorDescription = String
.format("Item %s: create version failed, a version with the name %s already exist",
itemId, versionName);
-
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY,
- LoggerTragetServiceName.CREATE_VERSION, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), errorDescription);
-
throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("VERSION_NAME_ALREADY_EXIST")
.withMessage(errorDescription)
.build());
}
@@ -553,14 +473,7 @@ public class VersioningManagerImpl implements VersioningManager {
String errorDescription = String
.format("Item %s: submit version failed, version %s is already Certified", itemId,
version.getId());
-
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
- LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), errorDescription);
-
throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("VERSION_ALREADY_CERTIFIED")
.withMessage(errorDescription)
.build());
}
@@ -634,7 +547,7 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoDeletedDao.delete(versionInfoDeletedEntity);
}
- private Version doCheckin(VersionInfoEntity versionInfoEntity, String checkinDescription) {
+ private Version doCheckin(VersionInfoEntity versionInfoEntity) {
UserCandidateVersion userCandidateVersion = versionInfoEntity.getCandidate();
versionInfoEntity.setCandidate(null);
versionInfoEntity.setActiveVersion(userCandidateVersion.getVersion());
@@ -649,8 +562,7 @@ public class VersioningManagerImpl implements VersioningManager {
return versionInfoEntity.getActiveVersion();
}
- private Version doSubmit(VersionInfoEntity versionInfoEntity, String submittingUser,
- String submitDescription) {
+ private Version doSubmit(VersionInfoEntity versionInfoEntity) {
Version finalVersion = versionInfoEntity.getActiveVersion().calculateNextFinal();
initVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
versionInfoEntity.getActiveVersion(), finalVersion);