From 36f192b978d3cd3bb11e524b80174eb6711eeb0a Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Fri, 15 Dec 2017 15:33:13 +0100 Subject: Code refactoring Change-Id: Iadcaf1006ccf400d41cfa5aa5674ce4af1376668 Issue-ID: CLAMP-93 Signed-off-by: Lukasz Muszkieta --- src/main/java/org/onap/clamp/clds/dao/CldsDao.java | 30 --- .../java/org/onap/clamp/clds/model/CldsModel.java | 266 +++------------------ .../org/onap/clamp/clds/service/CldsService.java | 12 +- 3 files changed, 29 insertions(+), 279 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index 7e42b296a..7bef430d9 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -65,7 +65,6 @@ public class CldsDao { private SimpleJdbcCall procGetTemplate; private SimpleJdbcCall procDelAllModelInstances; private SimpleJdbcCall procInsModelInstance; - private SimpleJdbcCall procDelModelInstance; private static final String HEALTHCHECK = "Select 1"; /** @@ -77,8 +76,6 @@ public class CldsDao { /** * When dataSource is provided, instantiate spring jdbc objects. - * - * @param dataSource */ public void setDataSource(DataSource dataSource) { this.jdbcTemplateObject = new JdbcTemplate(dataSource); @@ -90,15 +87,11 @@ public class CldsDao { this.procGetTemplate = new SimpleJdbcCall(dataSource).withProcedureName("get_template"); this.procSetTemplate = new SimpleJdbcCall(dataSource).withProcedureName("set_template"); this.procInsModelInstance = new SimpleJdbcCall(dataSource).withProcedureName("ins_model_instance"); - this.procDelModelInstance = new SimpleJdbcCall(dataSource).withProcedureName("del_model_instance"); this.procDelAllModelInstances = new SimpleJdbcCall(dataSource).withProcedureName("del_all_model_instances"); } /** * Get a model from the database given the model name. - * - * @param modelName - * @return model */ public CldsModel getModel(String modelName) { return getModel(modelName, null); @@ -106,9 +99,6 @@ public class CldsDao { /** * Get a model from the database given the controlNameUuid. - * - * @param controlNameUuid - * @return model */ public CldsModel getModelByUuid(String controlNameUuid) { return getModel(null, controlNameUuid); @@ -126,17 +116,9 @@ public class CldsDao { model.setId((String) (out.get("v_model_id"))); model.setTemplateId((String) (out.get("v_template_id"))); model.setTemplateName((String) (out.get("v_template_name"))); - model.setBpmnId((String) (out.get("v_template_bpmn_id"))); - model.setBpmnUserid((String) out.get("v_template_bpmn_user_id")); model.setBpmnText((String) out.get("v_template_bpmn_text")); - model.setPropId((String) (out.get("v_model_prop_id"))); - model.setPropUserid((String) out.get("v_model_prop_user_id")); model.setPropText((String) out.get("v_model_prop_text")); - model.setImageId((String) (out.get("v_template_image_id"))); - model.setImageUserid((String) out.get("v_template_image_user_id")); model.setImageText((String) out.get("v_template_image_text")); - model.setDocId((String) (out.get("v_template_doc_id"))); - model.setDocUserid((String) out.get("v_template_doc_user_id")); model.setDocText((String) out.get("v_template_doc_text")); model.setBlueprintText((String) out.get("v_model_blueprint_text")); model.getEvent().setId((String) (out.get("v_event_id"))); @@ -167,17 +149,9 @@ public class CldsDao { model.setId((String) (out.get("v_model_id"))); model.setTemplateId((String) (out.get("v_template_id"))); model.setTemplateName((String) (out.get("v_template_name"))); - model.setBpmnId((String) (out.get("v_template_bpmn_id"))); - model.setBpmnUserid((String) out.get("v_template_bpmn_user_id")); model.setBpmnText((String) out.get("v_template_bpmn_text")); - model.setPropId((String) (out.get("v_model_prop_id"))); - model.setPropUserid((String) out.get("v_model_prop_user_id")); model.setPropText((String) out.get("v_model_prop_text")); - model.setImageId((String) (out.get("v_template_image_id"))); - model.setImageUserid((String) out.get("v_template_image_user_id")); model.setImageText((String) out.get("v_template_image_text")); - model.setDocId((String) (out.get("v_template_doc_id"))); - model.setDocUserid((String) out.get("v_template_doc_user_id")); model.setDocText((String) out.get("v_template_doc_text")); model.setBlueprintText((String) out.get("v_model_blueprint_text")); model.getEvent().setId((String) (out.get("v_event_id"))); @@ -226,10 +200,6 @@ public class CldsDao { model.setControlNamePrefix((String) out.get("v_control_name_prefix")); model.setControlNameUuid((String) out.get("v_control_name_uuid")); model.setId((String) (out.get("v_model_id"))); - model.setPropId((String) (out.get("v_model_prop_id"))); - model.setPropUserid((String) (out.get("v_model_prop_user_id"))); - model.setBlueprintId((String) (out.get("v_model_blueprint_id"))); - model.setBlueprintUserid((String) out.get("v_model_blueprint_user_id")); model.getEvent().setId((String) (out.get("v_event_id"))); model.getEvent().setActionCd((String) out.get("v_action_cd")); model.getEvent().setActionStateCd((String) out.get("v_action_state_cd")); diff --git a/src/main/java/org/onap/clamp/clds/model/CldsModel.java b/src/main/java/org/onap/clamp/clds/model/CldsModel.java index 62b10d44f..55ea4ec21 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsModel.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsModel.java @@ -39,55 +39,34 @@ import org.onap.clamp.clds.dao.CldsDao; * Represent a CLDS Model. */ public class CldsModel { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsModel.class); - protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - - private static final int UUID_LENGTH = 36; - - public static final String STATUS_DESIGN = "DESIGN"; - public static final String STATUS_DISTRIBUTED = "DISTRIBUTED"; - public static final String STATUS_ACTIVE = "ACTIVE"; - public static final String STATUS_STOPPED = "STOPPED"; - public static final String STATUS_DELETING = "DELETING"; - public static final String STATUS_ERROR = "ERROR"; // manual - // intervention - // required - public static final String STATUS_UNKNOWN = "UNKNOWN"; - - private String id; - private String templateId; - private String templateName; - private String name; - private String controlNamePrefix; - private String controlNameUuid; - private String bpmnId; - private String bpmnUserid; - private String bpmnText; - private String propId; - private String propUserid; - private String propText; - private String imageId; - private String imageUserid; - private String imageText; - private String docId; - private String docUserid; - private String docText; - private String blueprintId; - private String blueprintUserid; - private String blueprintText; - private CldsEvent event; - private String status; - private List permittedActionCd; - private List cldsModelInstanceList; - - private String typeId; - private String typeName; - - private String dispatcherResponse; - - private String deploymentId; - - private boolean userAuthorizedToUpdate; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsModel.class); + private static final int UUID_LENGTH = 36; + private static final String STATUS_DESIGN = "DESIGN"; + private static final String STATUS_DISTRIBUTED = "DISTRIBUTED"; + private static final String STATUS_ACTIVE = "ACTIVE"; + private static final String STATUS_STOPPED = "STOPPED"; + private static final String STATUS_DELETING = "DELETING"; + private static final String STATUS_ERROR = "ERROR"; + private static final String STATUS_UNKNOWN = "UNKNOWN"; + private String id; + private String templateId; + private String templateName; + private String name; + private String controlNamePrefix; + private String controlNameUuid; + private String bpmnText; + private String propText; + private String imageText; + private String docText; + private String blueprintText; + private CldsEvent event; + private String status; + private List permittedActionCd; + private List cldsModelInstanceList; + private String typeId; + private String typeName; + private String deploymentId; /** * Construct empty model. @@ -98,10 +77,6 @@ public class CldsModel { /** * Retrieve from DB. - * - * @param cldsDao - * @param name - * @return */ public static CldsModel retrieve(CldsDao cldsDao, String name, boolean okIfNotFound) { // get from db @@ -126,9 +101,6 @@ public class CldsModel { /** * Save model to DB. - * - * @param cldsDao - * @param userid */ public void save(CldsDao cldsDao, String userid) { cldsDao.setModel(this, userid); @@ -136,32 +108,6 @@ public class CldsModel { determinePermittedActionCd(); } - /** - * Insert a new event for the new action. Throw IllegalArgumentException if - * requested actionCd is not permitted. - * - * @param cldsDao - * @param userid - * @param actionCd - * @param actionStateCd - */ - public void insEvent(CldsDao cldsDao, String userid, String actionCd, String actionStateCd) { - validateAction(actionCd); - event = CldsEvent.insEvent(cldsDao, this, userid, actionCd, actionStateCd, null); - determineStatus(); - determinePermittedActionCd(); - } - - /** - * Update event with processInstanceId - * - * @param cldsDao - * @param processInstanceId - */ - public void updEvent(CldsDao cldsDao, String processInstanceId) { - cldsDao.updEvent(event.getId(), processInstanceId); - } - /** * set the status in the model */ @@ -196,8 +142,6 @@ public class CldsModel { /** * Get the actionCd from current event. If none, default value is * CldsEvent.ACTION_CREATE - * - * @return */ private String getCurrentActionCd() { // current default actionCd is CREATE @@ -211,8 +155,6 @@ public class CldsModel { /** * Get the actionStateCd from current event. If none, default value is * CldsEvent.ACTION_STATE_COMPLETED - * - * @return */ private String getCurrentActionStateCd() { // current default actionStateCd is CREATE @@ -279,8 +221,6 @@ public class CldsModel { * Validate requestedActionCd - determine permittedActionCd and then check * if contained in permittedActionCd Throw IllegalArgumentException if * requested actionCd is not permitted. - * - * @param requestedActionCd */ public void validateAction(String requestedActionCd) { determinePermittedActionCd(); @@ -296,9 +236,6 @@ public class CldsModel { * + controlNameUuid). No fields are populated other than controlNamePrefix * and controlNameUuid. Throws BadRequestException if length of given * control name is less than UUID_LENGTH. - * - * @param fullControlName - * @return */ public static CldsModel createUsingControlName(String fullControlName) { if (fullControlName == null || fullControlName.length() < UUID_LENGTH) { @@ -321,9 +258,6 @@ public class CldsModel { /** * To insert modelInstance to the database - * - * @param cldsDao - * @param dcaeEvent */ public static CldsModel insertModelInstance(CldsDao cldsDao, DcaeEvent dcaeEvent, String userid) { String controlName = dcaeEvent.getControlName(); @@ -340,24 +274,6 @@ public class CldsModel { return cldsModel; } - /** - * To remove modelInstance from the database This method is defunct - DCAE - * Proxy will not undeploy individual instances. It will send an empty list - * of deployed instances to indicate all have been removed. Or it will send - * an updated list to indicate those that are still deployed with any not on - * the list considered undeployed. - * - * @param cldsDao - * @param dcaeEvent - */ - @SuppressWarnings("unused") - private static CldsModel removeModelInstance(CldsDao cldsDao, DcaeEvent dcaeEvent) { - String controlName = dcaeEvent.getControlName(); - // cldsModel = cldsDao.delModelInstance(cldsModel.getControlNameUuid(), - // dcaeEvent.getInstances() ); - return createUsingControlName(controlName); - } - /** * @return the name */ @@ -380,10 +296,6 @@ public class CldsModel { return typeName; } - /** - * @param name - * the typeName to set - */ public void setTypeName(String typeName) { this.typeName = typeName; } @@ -426,21 +338,6 @@ public class CldsModel { this.controlNameUuid = controlNameUuid; } - /** - * @return the propUserid - */ - public String getPropUserid() { - return propUserid; - } - - /** - * @param propUserid - * the propUserid to set - */ - public void setPropUserid(String propUserid) { - this.propUserid = propUserid; - } - /** * @return the propText */ @@ -479,14 +376,6 @@ public class CldsModel { this.templateName = templateName; } - public String getPropId() { - return propId; - } - - public void setPropId(String propId) { - this.propId = propId; - } - /** * @param event * the event to set @@ -510,37 +399,6 @@ public class CldsModel { this.status = status; } - /** - * @return the permittedActionCd - */ - public List getPermittedActionCd() { - return permittedActionCd; - } - - /** - * @param permittedActionCd - * the permittedActionCd to set - */ - public void setPermittedActionCd(List permittedActionCd) { - this.permittedActionCd = permittedActionCd; - } - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public String getBlueprintUserid() { - return blueprintUserid; - } - - public void setBlueprintUserid(String blueprintUserid) { - this.blueprintUserid = blueprintUserid; - } - public String getBlueprintText() { return blueprintText; } @@ -549,22 +407,6 @@ public class CldsModel { this.blueprintText = blueprintText; } - public String getBpmnId() { - return bpmnId; - } - - public void setBpmnId(String bpmnId) { - this.bpmnId = bpmnId; - } - - public String getBpmnUserid() { - return bpmnUserid; - } - - public void setBpmnUserid(String bpmnUserid) { - this.bpmnUserid = bpmnUserid; - } - public String getBpmnText() { return bpmnText; } @@ -573,22 +415,6 @@ public class CldsModel { this.bpmnText = bpmnText; } - public String getImageId() { - return imageId; - } - - public void setImageId(String imageId) { - this.imageId = imageId; - } - - public String getImageUserid() { - return imageUserid; - } - - public void setImageUserid(String imageUserid) { - this.imageUserid = imageUserid; - } - public String getImageText() { return imageText; } @@ -597,22 +423,6 @@ public class CldsModel { this.imageText = imageText; } - public String getDocId() { - return docId; - } - - public void setDocId(String docId) { - this.docId = docId; - } - - public String getDocUserid() { - return docUserid; - } - - public void setDocUserid(String docUserid) { - this.docUserid = docUserid; - } - public String getDocText() { return docText; } @@ -636,19 +446,6 @@ public class CldsModel { return cldsModelInstanceList; } - public void setCldsModelInstanceList(List cldsModelInstanceList) { - this.cldsModelInstanceList = cldsModelInstanceList; - } - - public void setDispatcherResponse(String dispatcherResponse) { - this.dispatcherResponse = dispatcherResponse; - - } - - public String getDispatcherResponse() { - return this.dispatcherResponse; - } - public String getDeploymentId() { return deploymentId; } @@ -657,11 +454,4 @@ public class CldsModel { this.deploymentId = deploymentId; } - public boolean isUserAuthorizedToUpdate() { - return userAuthorizedToUpdate; - } - - public void setUserAuthorizedToUpdate(boolean userAuthorizedToUpdate) { - this.userAuthorizedToUpdate = userAuthorizedToUpdate; - } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index bbcfd5d25..3c9e47046 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -151,13 +151,6 @@ public class CldsService extends SecureServiceBase { @Autowired private DcaeInventoryServices dcaeInventoryServices; - public CldsService() { - } - - public CldsService(RefProp refProp) { - this.refProp = refProp; - } - /* * * CLDS IFO service will return 3 things 1. User Name 2. CLDS code version @@ -295,7 +288,6 @@ public class CldsService extends SecureServiceBase { logger.debug("GET model for modelName={}", modelName); CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, false); isAuthorizedForVf(cldsModel); - cldsModel.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateCl)); /** * Checking condition whether our CLDS model can call INventory Method */ @@ -343,7 +335,6 @@ public class CldsService extends SecureServiceBase { if (template != null) { cldsModel.setTemplateId(template.getId()); cldsModel.setDocText(template.getPropText()); - cldsModel.setDocId(template.getPropId()); } } cldsModel.save(cldsDao, getUserId()); @@ -426,7 +417,6 @@ public class CldsService extends SecureServiceBase { if (template != null) { model.setTemplateId(template.getId()); model.setDocText(template.getPropText()); - model.setDocId(template.getPropId()); } } // save model to db @@ -833,7 +823,7 @@ public class CldsService extends SecureServiceBase { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public CldsModel deployModel(@PathParam("action") String action, @PathParam("modelName") String modelName, - @QueryParam("test") String test, CldsModel model) throws IOException { + @QueryParam("test") String test, CldsModel model) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName()); try { -- cgit 1.2.3-korg