summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java3
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/VersionDto.java34
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java55
-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/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java34
5 files changed, 93 insertions, 61 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java
index 499bd6e785..7bc1082ebe 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java
@@ -21,7 +21,8 @@
package org.openecomp.sdcrests.common;
public class RestConstants {
- public static final String USER_HEADER_PARAM = "USER_ID";
+ public static final String USER_ID_HEADER_PARAM = "USER_ID";
+ // value Should be equal to com.tlv.sdc.common.api.Constants#USER_ID_HEADER
public static final String USER_MISSING_ERROR_MSG =
"Field does not conform to predefined criteria : user : may not be null";
public static final String INVALID_JSON_ERROR_MESSAGE =
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/VersionDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/VersionDto.java
new file mode 100644
index 0000000000..b5b86c65a2
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/VersionDto.java
@@ -0,0 +1,34 @@
+package org.openecomp.sdcrests.common.types;
+
+/**
+ * Created by SVISHNEV on 3/5/2017.
+ */
+public class VersionDto {
+ String id;
+ String label;
+
+ public VersionDto(){
+
+ }
+
+ public VersionDto(String id, String label) {
+ this.id = id;
+ this.label = label;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java
index 67da814f48..af77268599 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java
@@ -22,6 +22,8 @@ package org.openecomp.sdcrests.errors;
import org.codehaus.jackson.map.JsonMappingException;
import org.hibernate.validator.internal.engine.path.PathImpl;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -32,8 +34,14 @@ import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
import org.openecomp.sdc.common.errors.GeneralErrorBuilder;
import org.openecomp.sdc.common.errors.JsonMappingErrorBuilder;
import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
-import org.slf4j.LoggerFactory;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -42,8 +50,8 @@ import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Path;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.core.Response;
public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE =
@@ -51,23 +59,28 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
private static Map<String, String> errorCodeToResponseStatus = JsonUtil
.json2Object(FileUtils.getFileInputStream(ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE),
Map.class);
- private static org.slf4j.Logger logger = LoggerFactory.getLogger(DefaultExceptionMapper.class);
+ private static Logger logger = (Logger) LoggerFactory.getLogger(DefaultExceptionMapper.class);
@Override
- public Response toResponse(Exception e0) {
+ public Response toResponse(Exception exception) {
Response response;
- if (e0 instanceof CoreException) {
- response = transform(CoreException.class.cast(e0));
- } else if (e0 instanceof ConstraintViolationException) {
- response = transform(ConstraintViolationException.class.cast(e0));
+ if (exception instanceof CoreException) {
+ response = transform(CoreException.class.cast(exception));
+ } else if (exception instanceof ConstraintViolationException) {
+ response = transform(ConstraintViolationException.class.cast(exception));
- } else if (e0 instanceof JsonMappingException) {
- response = transform(JsonMappingException.class.cast(e0));
+ } else if (exception instanceof JsonMappingException) {
+ response = transform(JsonMappingException.class.cast(exception));
} else {
- response = transform(e0);
+ response = transform(exception);
}
+ try {
+ writeStackTraceToFile(exception);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
List<Object> contentTypes = new ArrayList<>();
contentTypes.add(MediaType.APPLICATION_JSON);
response.getMetadata().put("Content-Type", contentTypes);
@@ -133,7 +146,6 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
.build();
}
-
private Response transform(JsonMappingException jsonMappingException) {
ErrorCode jsonMappingErrorCode = new JsonMappingErrorBuilder().build();
logger.error(jsonMappingErrorCode.message(), jsonMappingException);
@@ -143,9 +155,9 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
.build();
}
- private Response transform(Exception e0) {
- ErrorCode generalErrorCode = new GeneralErrorBuilder(e0.getMessage()).build();
- logger.error(generalErrorCode.message(), e0);
+ private Response transform(Exception exception) {
+ ErrorCode generalErrorCode = new GeneralErrorBuilder(exception.getMessage()).build();
+ logger.error(generalErrorCode.message(), exception);
return Response
.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, generalErrorCode))
@@ -160,4 +172,17 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
return new ErrorCodeAndMessage(status, code);
}
+ private void writeStackTraceToFile(Exception exception) throws IOException {
+ File file = new File("stack_trace.txt");
+ OutputStream outputStream = new FileOutputStream(file);
+
+ if(!file.exists()){
+ file.createNewFile();
+ }
+
+ PrintWriter printWriter = new PrintWriter(file);
+ exception.printStackTrace(printWriter);
+ printWriter.close();
+ }
+
}
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 7382ef72eb..6573485db7 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
@@ -22,20 +22,21 @@ package org.openecomp.sdcrests.mapping;
/**
* Base class for all mapping classes. Mapping classes will perform data mapping from source object
- * to target object Base class provides following<br>
- * <ol>
- * <li>provides life cycle of mapping class , first mapSimpleProperties is called and then
- * mapComplexProperties is called.</li>
- * <li>methods mapSimpleProperties and mapComplexProperties with default implementation,
- * these should be overridden by concrete mapping classes for writing mapping logic.</li>
- * </ol>
+ * to target object Base class provides following<br> <ol> <li>provides life cycle of
+ * mapping class , first mapSimpleProperties is called and then mapComplexProperties is
+ * called.</li> <li>methods mapSimpleProperties and mapComplexProperties with default
+ * implementation, these should be overridden by concrete mapping classes for writing mapping
+ * logic.</li> </ol>
+ *
+ *
*/
public abstract class MappingBase<S, T> {
/**
* Method is called for starting mapping from source object to target object method sets context
- * in the thread locale and than calls mapSimpleProperties and mapComplexProperties respectively.
+ * in the thread locale and than calls mapSimpleProperties and mapComplexProperties
+ * respectively.
*
* @param source : source object for mapping
* @param clazz : target <code>Class</code> for mapping
@@ -64,10 +65,9 @@ public abstract class MappingBase<S, T> {
}
/**
- * The actual method that does the mapping between the <code>source</code>
- * to <code>target</code> objects.
- * This method is being called automatically as part of the mapper class.
- * This method must be override (it is abstract) by the mapper class.
+ * The actual method that does the mapping between the <code>source</code> to <code>target</code>
+ * objects. This method is being called automatically as part of the mapper class. This
+ * method must be override (it is abstract) by the mapper class.
*
* @param source - the source object.
* @param target - the target object.
@@ -93,8 +93,8 @@ public abstract class MappingBase<S, T> {
try {
object = clazz.newInstance();
- } catch (InstantiationException | IllegalAccessException e0) {
- //Do nothing
+ } catch (InstantiationException | IllegalAccessException exception) {
+ //TODO: what what?
}
return object;
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java
index b8d47e4ef3..22ce0a4e45 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java
@@ -24,20 +24,12 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-/**
- * This class represents a generic collection wrapper to be used by paginated results.
- *
- * @param <T> the type parameter
- */
public class GenericCollectionWrapper<T> implements Serializable {
private static final long serialVersionUID = 1L;
private List<T> results;
private int listCount;
- /**
- * Instantiates a new Generic collection wrapper.
- */
public GenericCollectionWrapper() {
this.results = new ArrayList<>();
}
@@ -55,38 +47,18 @@ public class GenericCollectionWrapper<T> implements Serializable {
}
}
- /**
- * Gets results.
- *
- * @return the results
- */
public List<T> getResults() {
return results;
}
- /**
- * Sets results.
- *
- * @param results the results
- */
public void setResults(List<T> results) {
this.results = results;
}
- /**
- * Gets list count.
- *
- * @return the list count
- */
public int getListCount() {
return listCount;
}
- /**
- * Sets list count.
- *
- * @param listCount the list count
- */
public void setListCount(int listCount) {
this.listCount = listCount;
}
@@ -94,11 +66,11 @@ public class GenericCollectionWrapper<T> implements Serializable {
/**
* Add boolean.
*
- * @param e0 the e 0
+ * @param item the list item
* @return the boolean
*/
- public boolean add(T e0) {
- if (this.getResults().add(e0)) {
+ public boolean add(T item) {
+ if (this.getResults().add(item)) {
this.setListCount(this.getResults().size());
return true;
}