From 7be9c5161726e715804b80bf9052547d8ee60262 Mon Sep 17 00:00:00 2001 From: Safran Date: Mon, 23 Aug 2021 18:03:25 -0400 Subject: [PATCH] More work on caNano 726 --- .../restful/sample/NanomaterialEntityBO.java | 20 +++++++++++++++++-- .../impl/CompositionServiceLocalImpl.java | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/software/cananolab-webapp/src/gov/nih/nci/cananolab/restful/sample/NanomaterialEntityBO.java b/software/cananolab-webapp/src/gov/nih/nci/cananolab/restful/sample/NanomaterialEntityBO.java index 1022e5af15..47caed8d42 100644 --- a/software/cananolab-webapp/src/gov/nih/nci/cananolab/restful/sample/NanomaterialEntityBO.java +++ b/software/cananolab-webapp/src/gov/nih/nci/cananolab/restful/sample/NanomaterialEntityBO.java @@ -40,6 +40,7 @@ import gov.nih.nci.cananolab.util.DateUtils; import gov.nih.nci.cananolab.util.StringUtils; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashSet; @@ -424,11 +425,17 @@ private NanomaterialEntityBean transferNanoMateriaEntityBean( comp.setId(simpleCompBean.getId()); comp.setCreatedBy(simpleCompBean.getCreatedBy()); comp.setCreatedDate(simpleCompBean.getCreatedDate()); - } else { + } else if ((nanoBean.getId()!=null)&&(nanoBean.getId()>0)){ //TODO see if there is a way to grab user directly comp.setCreatedBy(nanoBean.getCreatedBy()); comp.setCreatedDate(nanoBean.getCreatedDate()); + } else { + String currentUser = SpringSecurityUtil.getLoggedInUserName(); + comp.setCreatedBy(currentUser); + comp.setCreatedDate(Calendar.getInstance().getTime()); } + + comp.setMolecularFormula(simpleCompBean.getMolecularFormula()); comp.setMolecularFormulaType(simpleCompBean.getMolecularFormulaType()); comp.setValue(simpleCompBean.getValue()); @@ -487,8 +494,17 @@ private NanomaterialEntityBean transferNanoMateriaEntityBean( comp.setName(simpleComp.getName()); comp.setPubChemDataSourceName(simpleComp.getPubChemDataSourceName()); comp.setPubChemId(simpleComp.getPubChemId()); - if(simpleComp.getId()!=null && simpleComp.getId()>0) { +// if(simpleComp.getId()!=null && simpleComp.getId()>0) { +// comp.setId(simpleComp.getId()); +// } + if((simpleComp.getId()!=null)&&(simpleComp.getId()>0)){ comp.setId(simpleComp.getId()); + comp.setCreatedBy(simpleComp.getCreatedBy()); + comp.setCreatedDate(simpleComp.getCreatedDate()); + } else { + //TODO see if there is a way to grab user directly + comp.setCreatedBy(nanoBean.getCreatedBy()); + comp.setCreatedDate(nanoBean.getCreatedDate()); } comp.setCreatedBy(simpleComp.getCreatedBy()); comp.setCreatedDate(simpleComp.getCreatedDate()); diff --git a/software/cananolab-webapp/src/gov/nih/nci/cananolab/service/sample/impl/CompositionServiceLocalImpl.java b/software/cananolab-webapp/src/gov/nih/nci/cananolab/service/sample/impl/CompositionServiceLocalImpl.java index 7a2c7f91ee..59bb252409 100644 --- a/software/cananolab-webapp/src/gov/nih/nci/cananolab/service/sample/impl/CompositionServiceLocalImpl.java +++ b/software/cananolab-webapp/src/gov/nih/nci/cananolab/service/sample/impl/CompositionServiceLocalImpl.java @@ -34,10 +34,13 @@ import gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper; import gov.nih.nci.cananolab.system.applicationservice.CaNanoLabApplicationService; import gov.nih.nci.cananolab.system.applicationservice.client.ApplicationServiceProvider; + +import java.util.Calendar; import java.util.Collection; import java.util.HashSet; import java.util.List; +import gov.nih.nci.cananolab.util.Constants; import org.apache.log4j.Hierarchy; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -75,6 +78,12 @@ public void saveNanomaterialEntity(SampleBean sampleBean, NanomaterialEntityBean .getApplicationService(); NanomaterialEntity entity = entityBean.getDomainEntity(); logger.debug("NanomaterialEntity " + entity.getCreatedBy()); + String currentUser = SpringSecurityUtil.getLoggedInUserName() ; + if((entity.getId()==null)||!(entity.getId()>0) ){ + entity.setCreatedBy(currentUser); + entity.setCreatedDate(Calendar.getInstance().getTime()); + } + entity.setCreatedBy(currentUser); Boolean newEntity = true; Boolean newComp = true; if (entity.getId() != null) {