diff options
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping')
2 files changed, 57 insertions, 73 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/EchoMapMapping.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/EchoMapMapping.java index 0d394eb9aa..688b49c6e0 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/EchoMapMapping.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/EchoMapMapping.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.mapping; import java.util.Map; @@ -23,8 +22,8 @@ import java.util.Map; */ public class EchoMapMapping extends MappingBase<Map<String, String>, Map<String, String>> { - @Override - public void doMapping(Map<String, String> source, Map<String, String> target) { - target.putAll(source); - } + @Override + public void doMapping(Map<String, String> source, Map<String, String> target) { + target.putAll(source); + } } 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 8b6fca5ae1..68a16e854c 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 @@ -13,86 +13,71 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.mapping; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCode; /** - * 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> - * - * + * 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> */ - 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. - * - * @param source : source object for mapping - * @param clazz : target <code>Class</code> for mapping - * @return <code>T</code> - instance of type <code>T</code> - */ - - public final T applyMapping(final S source, Class<T> clazz) { - T target = (T) instantiateTarget(clazz); - if (source != null && target != null) { - preMapping(source, target); - doMapping(source, target); - postMapping(source, target); - + /** + * 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. + * + * @param source : source object for mapping + * @param clazz : target <code>Class</code> for mapping + * @return <code>T</code> - instance of type <code>T</code> + */ + public final T applyMapping(final S source, Class<T> clazz) { + T target = (T) instantiateTarget(clazz); + if (source != null && target != null) { + preMapping(source, target); + doMapping(source, target); + postMapping(source, target); + } + return target; } - return target; - - } - /** - * This method is called before the <code>doMapping</code> method. - */ - public void preMapping(final S source, T target) { - // extension point - } - - /** - * 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. - */ - - public abstract void doMapping(final S source, T target); - - /** - * This method is called after the <code>doMapping</code> method. - */ - public void postMapping(final S source, T target) { - // extension point - } - - /** - * Creates the instance of the input class. - * - * @return <code>Object</code> - */ + /** + * This method is called before the <code>doMapping</code> method. + */ + public void preMapping(final S source, T target) { + // extension point + } - private Object instantiateTarget(final Class<?> clazz) { + /** + * 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. + */ + public abstract void doMapping(final S source, T target); + + /** + * This method is called after the <code>doMapping</code> method. + */ + public void postMapping(final S source, T target) { + // extension point + } - try { - return clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException exception ) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(exception.getMessage()).build(), exception); + /** + * Creates the instance of the input class. + * + * @return <code>Object</code> + */ + private Object instantiateTarget(final Class<?> clazz) { + try { + return clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException exception) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(exception.getMessage()).build(), exception); + } } - } } - |