Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<!-- Monitoring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jooq.Record;
import org.jooq.SelectQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -28,9 +29,16 @@ public UserDaoImpl(DSLContext dslContext) {
}

public AuthUser get(String emailAddress) {
return dslContext.selectFrom(AUTH_USER)
.where(AUTH_USER.EMAIL_ADDRESS.eq(emailAddress))
.fetchOne().into(AuthUser.class);

try
{
return dslContext.selectFrom(AUTH_USER)
.where(AUTH_USER.EMAIL_ADDRESS.eq(emailAddress))
.fetchOne().into(AuthUser.class);
}
catch (Exception e){
return null;
}
}

public List<AuthUser> list(){
Expand Down
62 changes: 27 additions & 35 deletions src/main/java/edu/mit/cci/pogs/service/ChatScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import edu.mit.cci.pogs.model.dao.chatscripthasresearchgroup.ChatScriptHasResearchGroupDao;
import edu.mit.cci.pogs.model.jooq.tables.pojos.ChatScriptHasResearchGroup;
import edu.mit.cci.pogs.model.jooq.tables.pojos.ChatScript;
import edu.mit.cci.pogs.service.base.ServiceBase;
import edu.mit.cci.pogs.utils.ObjectUtils;
import edu.mit.cci.pogs.view.chatscript.beans.ChatScriptBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -13,9 +15,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@Service
public class ChatScriptService {
public class ChatScriptService extends ServiceBase {

private ChatEntryDao chatEntryDao;
private ChatScriptDao chatScriptDao;
Expand Down Expand Up @@ -63,54 +67,42 @@ private void createOrUpdateUserGroups(ChatScriptBean chatScriptBean) {
if (chatScriptBean.getResearchGroupRelationshipBean() == null && chatScriptBean.getResearchGroupRelationshipBean().getSelectedValues() == null) {
return;
}
List<ChatScriptHasResearchGroup> toCreate = new ArrayList<>();
List<ChatScriptHasResearchGroup> toDelete = new ArrayList<>();
List<Long> toCreate = new ArrayList<>();
List<Long> toDelete = new ArrayList<>();
List<ChatScriptHasResearchGroup> currentlySelected = listChatScriptHasResearchGroupByChatScript(chatScriptBean.getId());

for (ChatScriptHasResearchGroup rghau : currentlySelected) {
boolean foundRGH = false;
for (String researchGroupId : chatScriptBean.getResearchGroupRelationshipBean().getSelectedValues()) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
foundRGH = true;
}
}
if (!foundRGH) {
toDelete.add(rghau);
}
List<Long> currentResearchGroups = currentlySelected
.stream()
.map(ChatScriptHasResearchGroup::getResearchGroupId)
.collect(Collectors.toList());

}
String[] newSelectedValues = chatScriptBean.getResearchGroupRelationshipBean().getSelectedValues();

UpdateResearchGroups(toCreate, toDelete, currentResearchGroups, newSelectedValues);

for (String researchGroupId : chatScriptBean.getResearchGroupRelationshipBean().getSelectedValues()) {
for (Long toCre : toCreate) {
ChatScriptHasResearchGroup rghau = new ChatScriptHasResearchGroup();
rghau.setChatScriptId(chatScriptBean.getId());
rghau.setResearchGroupId(toCre);
chatScriptHasResearchGroupDao.create(rghau);
}
for (Long toDel : toDelete) {

boolean selectedAlreadyIn = false;
for (ChatScriptHasResearchGroup rghau : currentlySelected) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
selectedAlreadyIn = true;
}
}
if (!selectedAlreadyIn) {
ChatScriptHasResearchGroup rghau = new ChatScriptHasResearchGroup();
rghau.setChatScriptId(chatScriptBean.getId());
rghau.setResearchGroupId(new Long(researchGroupId));
toCreate.add(rghau);
}
ChatScriptHasResearchGroup rghau = currentlySelected
.stream()
.filter(a -> (a.getChatScriptId() == chatScriptBean.getId() && a.getResearchGroupId() == toDel))
.findFirst().get();

}
for (ChatScriptHasResearchGroup toCre : toCreate) {
chatScriptHasResearchGroupDao.create(toCre);
}
for (ChatScriptHasResearchGroup toDel : toDelete) {
chatScriptHasResearchGroupDao.delete(toDel);
chatScriptHasResearchGroupDao.delete(rghau);
}

}

public ChatScript createOrUpdate(ChatScriptBean chatScriptBean) {

ChatScript chatScript = new ChatScript();
chatScript.setId(chatScriptBean.getId());
chatScript.setChatScriptName(chatScriptBean.getChatScriptName());

ObjectUtils.Copy(chatScript, chatScriptBean);

if (chatScript.getId() == null) {
chatScript = chatScriptDao.create(chatScript);
Expand Down
77 changes: 34 additions & 43 deletions src/main/java/edu/mit/cci/pogs/service/DictionaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import edu.mit.cci.pogs.model.jooq.tables.pojos.Dictionary;
import edu.mit.cci.pogs.model.jooq.tables.pojos.DictionaryHasResearchGroup;
import edu.mit.cci.pogs.model.jooq.tables.pojos.StudyHasResearchGroup;
import edu.mit.cci.pogs.service.base.ServiceBase;
import edu.mit.cci.pogs.utils.ObjectUtils;
import edu.mit.cci.pogs.view.dictionary.beans.DictionaryBean;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -19,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -37,7 +40,7 @@
import edu.mit.cci.pogs.view.dictionary.beans.DictionaryEntriesBean;

@Service
public class DictionaryService {
public class DictionaryService extends ServiceBase {

private final DictionaryDao dictionaryDao;
private final DictionaryEntryDao dictionaryEntryDao;
Expand Down Expand Up @@ -102,56 +105,44 @@ private void createOrUpdateUserGroups(DictionaryBean dictionaryBean) {
if (dictionaryBean.getResearchGroupRelationshipBean() == null && dictionaryBean.getResearchGroupRelationshipBean().getSelectedValues() == null) {
return;
}
List<DictionaryHasResearchGroup> toCreate = new ArrayList<>();
List<DictionaryHasResearchGroup> toDelete = new ArrayList<>();

List<Long> toCreate = new ArrayList<>();
List<Long> toDelete = new ArrayList<>();
List<DictionaryHasResearchGroup> currentlySelected = listDictionaryHasResearchGroupByDictionaryId(dictionaryBean.getId());

for (DictionaryHasResearchGroup rghau : currentlySelected) {
boolean foundRGH = false;
for (String researchGroupId : dictionaryBean.getResearchGroupRelationshipBean().getSelectedValues()) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
foundRGH = true;
}
}
if (!foundRGH) {
toDelete.add(rghau);
}

}


for (String researchGroupId : dictionaryBean.getResearchGroupRelationshipBean().getSelectedValues()) {

boolean selectedAlreadyIn = false;
for (DictionaryHasResearchGroup rghau : currentlySelected) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
selectedAlreadyIn = true;
}
}
if (!selectedAlreadyIn) {
DictionaryHasResearchGroup rghau = new DictionaryHasResearchGroup();
rghau.setDictionaryId(dictionaryBean.getId());
rghau.setResearchGroupId(new Long(researchGroupId));
toCreate.add(rghau);
}

}
for (DictionaryHasResearchGroup toCre : toCreate) {
dictionaryHasResearchGroupDao.create(toCre);

List<Long> currentResearchGroups = currentlySelected
.stream()
.map(DictionaryHasResearchGroup::getResearchGroupId)
.collect(Collectors.toList());

String[] newSelectedValues = dictionaryBean.getResearchGroupRelationshipBean().getSelectedValues();

UpdateResearchGroups(toCreate, toDelete, currentResearchGroups, newSelectedValues);


for (Long toCre : toCreate) {
DictionaryHasResearchGroup rghau = new DictionaryHasResearchGroup();
rghau.setDictionaryId(dictionaryBean.getId());
rghau.setResearchGroupId(toCre);
dictionaryHasResearchGroupDao.create(rghau);
}
for (DictionaryHasResearchGroup toDel : toDelete) {
dictionaryHasResearchGroupDao.delete(toDel);
for (Long toDel : toDelete) {

DictionaryHasResearchGroup rghau = currentlySelected
.stream()
.filter(a -> (a.getDictionaryId() == dictionaryBean.getId() && a.getResearchGroupId() == toDel))
.findFirst().get();

dictionaryHasResearchGroupDao.delete(rghau);
}

}

public Dictionary createOrUpdate(DictionaryBean dictionaryBean) {

Dictionary dictionary = new Dictionary();
dictionary.setId(dictionaryBean.getId());
dictionary.setDictionaryName(dictionaryBean.getDictionaryName());
dictionary.setHasGroundTruth(dictionaryBean.getHasGroundTruth() == null ? false : dictionaryBean.getHasGroundTruth());


ObjectUtils.Copy(dictionary, dictionaryBean);

if (dictionary.getId() == null) {
dictionary = dictionaryDao.create(dictionary);
dictionaryBean.setId(dictionary.getId());
Expand Down
64 changes: 27 additions & 37 deletions src/main/java/edu/mit/cci/pogs/service/ExecutableScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import edu.mit.cci.pogs.model.dao.executablescripthasresearchgroup.ExecutableScriptHasResearchGroupDao;
import edu.mit.cci.pogs.model.jooq.tables.pojos.ExecutableScript;
import edu.mit.cci.pogs.model.jooq.tables.pojos.ExecutableScriptHasResearchGroup;
import edu.mit.cci.pogs.service.base.ServiceBase;
import edu.mit.cci.pogs.utils.ObjectUtils;
import edu.mit.cci.pogs.view.executablescript.beans.ExecutableScriptBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ExecutableScriptService {
public class ExecutableScriptService extends ServiceBase {

private final ExecutableScriptHasResearchGroupDao executableScriptHasResearchGroupDao;
private final ExecutableScriptDao executableScriptDao;
Expand All @@ -35,45 +38,34 @@ private void createOrUpdateUserGroups(ExecutableScriptBean executableScriptBean)
if (executableScriptBean.getResearchGroupRelationshipBean() == null && executableScriptBean.getResearchGroupRelationshipBean().getSelectedValues() == null) {
return;
}
List<ExecutableScriptHasResearchGroup> toCreate = new ArrayList<>();
List<ExecutableScriptHasResearchGroup> toDelete = new ArrayList<>();

List<Long> toCreate = new ArrayList<>();
List<Long> toDelete = new ArrayList<>();
List<ExecutableScriptHasResearchGroup> currentlySelected = listExecutableScriptHasResearchGroupByDictionaryId(executableScriptBean.getId());

for (ExecutableScriptHasResearchGroup rghau : currentlySelected) {
boolean foundRGH = false;
for (String researchGroupId : executableScriptBean.getResearchGroupRelationshipBean().getSelectedValues()) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
foundRGH = true;
}
}
if (!foundRGH) {
toDelete.add(rghau);
}
List<Long> currentResearchGroups = currentlySelected
.stream()
.map(ExecutableScriptHasResearchGroup::getResearchGroupId)
.collect(Collectors.toList());

}
String[] newSelectedValues = executableScriptBean.getResearchGroupRelationshipBean().getSelectedValues();

UpdateResearchGroups(toCreate, toDelete, currentResearchGroups, newSelectedValues);

for (String researchGroupId : executableScriptBean.getResearchGroupRelationshipBean().getSelectedValues()) {
for (Long toCre : toCreate) {
ExecutableScriptHasResearchGroup rghau = new ExecutableScriptHasResearchGroup();
rghau.setExecutableScriptId(executableScriptBean.getId());
rghau.setResearchGroupId(toCre);
executableScriptHasResearchGroupDao.create(rghau);
}
for (Long toDel : toDelete) {

boolean selectedAlreadyIn = false;
for (ExecutableScriptHasResearchGroup rghau : currentlySelected) {
if (rghau.getResearchGroupId().longValue() == new Long(researchGroupId).longValue()) {
selectedAlreadyIn = true;
}
}
if (!selectedAlreadyIn) {
ExecutableScriptHasResearchGroup rghau = new ExecutableScriptHasResearchGroup();
rghau.setExecutableScriptId(executableScriptBean.getId());
rghau.setResearchGroupId(new Long(researchGroupId));
toCreate.add(rghau);
}
ExecutableScriptHasResearchGroup rghau = currentlySelected
.stream()
.filter(a -> (a.getExecutableScriptId() == executableScriptBean.getId() && a.getResearchGroupId() == toDel))
.findFirst().get();

}
for (ExecutableScriptHasResearchGroup toCre : toCreate) {
executableScriptHasResearchGroupDao.create(toCre);
}
for (ExecutableScriptHasResearchGroup toDel : toDelete) {
executableScriptHasResearchGroupDao.delete(toDel);
executableScriptHasResearchGroupDao.delete(rghau);
}

}
Expand All @@ -82,10 +74,8 @@ private void createOrUpdateUserGroups(ExecutableScriptBean executableScriptBean)
public ExecutableScript createOrUpdate(ExecutableScriptBean executableScriptBean) {

ExecutableScript executableScript = new ExecutableScript();
executableScript.setId(executableScriptBean.getId());
executableScript.setScriptContent(executableScriptBean.getScriptContent());
executableScript.setScriptName(executableScriptBean.getScriptName());
executableScript.setScriptType(executableScriptBean.getScriptType());

ObjectUtils.Copy(executableScript, executableScriptBean);

if (executableScript.getId() == null) {
executableScript = executableScriptDao.create(executableScript);
Expand Down
Loading