-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add-noteservice-Tests #1309
Open
Agaba-derrick
wants to merge
2
commits into
I-TECH-UW:develop
Choose a base branch
from
Agaba-derrick:Add-note-Tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add-noteservice-Tests #1309
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mherman22
suggested changes
Nov 17, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Please add all tests from the service methods at
OpenELIS-Global-2/src/main/java/org/openelisglobal/note/service/NoteServiceImpl.java
Lines 97 to 440 in 94630df
public String getNotesAsString(NoteObject noteObject, boolean prefixType, boolean prefixTimestamp, | |
String noteSeparator, NoteType[] filter, boolean excludeExternPrefix) { | |
return getNotesAsString(noteObject, prefixType, prefixTimestamp, noteSeparator, filter, excludeExternPrefix, | |
EncodeContext.HTML); | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public String getNotesAsString(NoteObject noteObject, boolean prefixType, boolean prefixTimestamp, | |
String noteSeparator, NoteType[] filter, boolean excludeExternPrefix, EncodeContext context) { | |
boolean includeNoneConformity = false; | |
List<String> dbFilter = new ArrayList<>(filter.length); | |
for (NoteType type : filter) { | |
if (type == NoteType.NON_CONFORMITY) { | |
includeNoneConformity = true; | |
} | |
dbFilter.add(type.getDBCode()); | |
} | |
List<Note> noteList = getNotesChronologicallyByRefIdAndRefTableAndType(noteObject.getObjectId(), | |
noteObject.getTableId(), dbFilter); | |
if (includeNoneConformity) { | |
List<Note> nonConformityNoteList = getNonConformityReasons(noteObject); | |
if (!nonConformityNoteList.isEmpty()) { | |
noteList.addAll(nonConformityNoteList); | |
Collections.sort(noteList, new Comparator<Note>() { | |
@Override | |
public int compare(Note o1, Note o2) { | |
return o1.getLastupdated().compareTo(o2.getLastupdated()); | |
} | |
}); | |
} | |
} | |
return notesToString(noteObject, prefixType, prefixTimestamp, noteSeparator, noteList, excludeExternPrefix, | |
context); | |
} | |
private List<Note> getNonConformityReasons(NoteObject noteObject) { | |
ArrayList<Note> notes = new ArrayList<>(); | |
if (noteObject.getBoundTo() == BoundTo.QA_EVENT) { | |
return notes; | |
} | |
ArrayList<String> filter = new ArrayList<>(1); | |
filter.add(NoteType.NON_CONFORMITY.getDBCode()); | |
Sample sample = null; | |
SampleItem sampleItem = null; | |
// get parent objects and the qa notes | |
if (noteObject.getBoundTo() == BoundTo.ANALYSIS) { | |
sampleItem = ((Analysis) noteObject).getSampleItem(); | |
notes.addAll(getNotesChronologicallyByRefIdAndRefTableAndType(sampleItem.getId(), | |
SampleItemServiceImpl.getSampleItemTableReferenceId(), filter)); | |
sample = sampleItem.getSample(); | |
notes.addAll(baseObjectDAO.getNotesChronologicallyByRefIdAndRefTableAndType(sample.getId(), | |
SampleServiceImpl.getTableReferenceId(), filter)); | |
} else if (noteObject.getBoundTo() == BoundTo.SAMPLE_ITEM) { | |
sampleItem = (SampleItem) noteObject; | |
sample = sampleItem.getSample(); | |
notes.addAll(baseObjectDAO.getNotesChronologicallyByRefIdAndRefTableAndType(sample.getId(), | |
SampleServiceImpl.getTableReferenceId(), filter)); | |
} | |
if (sample != null) { | |
List<SampleQaEvent> sampleQAList = sampleQAService.getSampleQaEventsBySample(sample); | |
for (SampleQaEvent event : sampleQAList) { | |
if (sampleItem == null || event.getSampleItem() == null | |
|| sampleItem.getId().equals(event.getSampleItem().getId())) { | |
notes.addAll(baseObjectDAO.getNotesChronologicallyByRefIdAndRefTableAndType(event.getId(), | |
QAService.TABLE_REFERENCE_ID, filter)); | |
Note proxyNote = new Note(); | |
proxyNote.setNoteType(Note.NON_CONFORMITY); | |
proxyNote.setText(event.getQaEvent().getLocalizedName()); | |
proxyNote.setLastupdated(event.getLastupdated()); | |
notes.add(proxyNote); | |
} | |
} | |
} | |
return notes; | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public String getNotesAsString(NoteObject noteObject, boolean prefixType, boolean prefixTimestamp, | |
String noteSeparator, boolean excludeExternPrefix) { | |
return getNotesAsString(noteObject, prefixType, prefixTimestamp, noteSeparator, excludeExternPrefix, | |
EncodeContext.HTML); | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public String getNotesAsString(NoteObject noteObject, boolean prefixType, boolean prefixTimestamp, | |
String noteSeparator, boolean excludeExternPrefix, EncodeContext context) { | |
List<Note> noteList = getNotesChronologicallyByRefIdAndRefTable(noteObject.getObjectId(), | |
noteObject.getTableId()); | |
return notesToString(noteObject, prefixType, prefixTimestamp, noteSeparator, noteList, excludeExternPrefix, | |
context); | |
} | |
private String notesToString(NoteObject noteObject, boolean prefixType, boolean prefixTimestamp, | |
String noteSeparator, List<Note> noteList, boolean excludeExternPrefix, EncodeContext context) { | |
if (noteList.isEmpty()) { | |
return null; | |
} | |
StringBuilder builder = new StringBuilder(); | |
for (Note note : noteList) { | |
if (prefixType) { | |
builder.append(StringUtil.encodeForContext(getNotePrefix(note, excludeExternPrefix), context)); | |
builder.append(" "); | |
} | |
if (prefixTimestamp) { | |
builder.append(StringUtil.encodeForContext(getNoteTimestamp(note), context)); | |
builder.append(" "); | |
} | |
if (prefixType || prefixTimestamp) { | |
builder.append(": "); | |
} | |
builder.append(StringUtil.encodeForContext(note.getText(), context)); | |
builder.append(StringUtil.blankIfNull(noteSeparator)); | |
} | |
if (!GenericValidator.isBlankOrNull(noteSeparator)) { | |
builder.setLength(builder.lastIndexOf(noteSeparator)); | |
} | |
return builder.toString(); | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public List<Note> getNotes(NoteObject noteObject) { | |
return getNotesChronologicallyByRefIdAndRefTable(noteObject.getObjectId(), noteObject.getTableId()); | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public String getNotesAsString(NoteObject noteObject, String prefix, String noteSeparator) { | |
List<Note> noteList = getNotesChronologicallyByRefIdAndRefTable(noteObject.getObjectId(), | |
noteObject.getTableId()); | |
if (noteList.isEmpty()) { | |
return null; | |
} | |
StringBuilder builder = new StringBuilder(); | |
for (Note note : noteList) { | |
builder.append(StringUtil.blankIfNull(prefix)); | |
builder.append(note.getText()); | |
builder.append(StringUtil.blankIfNull(noteSeparator)); | |
} | |
if (!GenericValidator.isBlankOrNull(noteSeparator)) { | |
builder.setLength(builder.lastIndexOf(noteSeparator)); | |
} | |
return builder.toString(); | |
} | |
@Transactional(readOnly = true) | |
@Override | |
public Note getMostRecentNoteFilteredBySubject(NoteObject noteObject, String filter) { | |
List<Note> noteList; | |
if (GenericValidator.isBlankOrNull(filter)) { | |
noteList = getNotesChronologicallyByRefIdAndRefTable(noteObject.getObjectId(), noteObject.getTableId()); | |
if (!noteList.isEmpty()) { | |
return noteList.get(noteList.size() - 1); | |
} | |
} else { | |
noteList = getNoteByRefIAndRefTableAndSubject(noteObject.getObjectId(), noteObject.getTableId(), filter); | |
if (!noteList.isEmpty()) { | |
return noteList.get(0); | |
} | |
} | |
return null; | |
} | |
private String getNoteTimestamp(Note note) { | |
return DateUtil.convertTimestampToStringDateAndTime(note.getLastupdated()); | |
} | |
@Override | |
public Note createSavableNote(NoteObject noteObject, NoteType type, String text, String subject, | |
String currentUserId) { | |
if (GenericValidator.isBlankOrNull(text)) { | |
return null; | |
} | |
Note note = new Note(); | |
note.setReferenceId(noteObject.getObjectId()); | |
note.setReferenceTableId(noteObject.getTableId()); | |
note.setNoteType(type.getDBCode()); | |
note.setSubject(subject); | |
note.setText(text); | |
note.setSysUserId(currentUserId); | |
note.setSystemUser(createSystemUser(currentUserId)); | |
return note; | |
} | |
public static SystemUser createSystemUser(String currentUserId) { | |
SystemUser systemUser = new SystemUser(); | |
systemUser.setId(currentUserId); | |
SpringContext.getBean(SystemUserService.class).getData(systemUser); | |
return systemUser; | |
} | |
public static String getReferenceTableIdForNoteBinding(BoundTo binding) { | |
switch (binding) { | |
case ANALYSIS: { | |
return AnalysisServiceImpl.getTableReferenceId(); | |
} | |
case QA_EVENT: { | |
return QAService.TABLE_REFERENCE_ID; | |
} | |
case SAMPLE: { | |
return SampleServiceImpl.getTableReferenceId(); | |
} | |
case SAMPLE_ITEM: { | |
return SampleItemServiceImpl.getSampleItemTableReferenceId(); | |
} | |
default: { | |
return null; | |
} | |
} | |
} | |
public List<Note> getTestNotesInDateRangeByType(Date lowDate, Date highDate, NoteType noteType) { | |
return baseObjectDAO.getNotesInDateRangeAndType(lowDate, DateUtil.addDaysToSQLDate(highDate, 1), | |
noteType.DBCode, AnalysisServiceImpl.getTableReferenceId()); | |
} | |
private String getNotePrefix(Note note, boolean excludeExternPrefix) { | |
if (SUPPORT_INTERNAL_EXTERNAL) { | |
if (Note.INTERNAL.equals(note.getNoteType())) { | |
return MessageUtil.getMessage("note.type.internal"); | |
} else if (Note.EXTERNAL.equals(note.getNoteType())) { | |
return excludeExternPrefix ? "" : MessageUtil.getMessage("note.type.external"); | |
} else if (Note.REJECT_REASON.equals(note.getNoteType())) { | |
return MessageUtil.getMessage("note.type.rejectReason"); | |
} else if (Note.NON_CONFORMITY.equals(note.getNoteType())) { | |
return MessageUtil.getMessage("note.type.nonConformity"); | |
} | |
} | |
return ""; | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public Note getData(String noteId) { | |
return getBaseObjectDAO().getData(noteId); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getNotesByNoteTypeRefIdRefTable(Note note) { | |
Map<String, Object> propertyValues = new HashMap<>(); | |
propertyValues.put("referenceId", note.getReferenceId()); | |
propertyValues.put("referenceTableId", note.getReferenceTableId()); | |
propertyValues.put("noteType", note.getNoteType()); | |
return getBaseObjectDAO().getAllMatchingOrdered(propertyValues, "lastupdated", false); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getNotesInDateRangeAndType(Date lowDate, Date highDate, String noteType, | |
String referenceTableId) { | |
return getBaseObjectDAO().getNotesInDateRangeAndType(lowDate, highDate, noteType, referenceTableId); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getAllNotesByRefIdRefTable(Note note) { | |
return getBaseObjectDAO().getAllNotesByRefIdRefTable(note); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getNotesChronologicallyByRefIdAndRefTable(String refId, String table_id) { | |
Map<String, Object> propertyValues = new HashMap<>(); | |
propertyValues.put("referenceId", refId); | |
propertyValues.put("referenceTableId", table_id); | |
return baseObjectDAO.getAllMatchingOrdered(propertyValues, "lastupdated", false); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getNotesChronologicallyByRefIdAndRefTableAndType(String objectId, String tableId, | |
List<String> filter) { | |
return getBaseObjectDAO().getNotesChronologicallyByRefIdAndRefTableAndType(objectId, tableId, filter); | |
} | |
@Override | |
@Transactional(readOnly = true) | |
public List<Note> getNoteByRefIAndRefTableAndSubject(String refId, String table_id, String subject) { | |
Map<String, Object> propertyValues = new HashMap<>(); | |
propertyValues.put("referenceId", refId); | |
propertyValues.put("referenceTableId", table_id); | |
propertyValues.put("subject", subject); | |
return baseObjectDAO.getAllMatching(propertyValues); | |
} | |
@Override | |
public String insert(Note note) { | |
if (getBaseObjectDAO().duplicateNoteExists(note)) { | |
throw new LIMSDuplicateRecordException("Duplicate record exists for " + note.getNoteType()); | |
} | |
return super.insert(note); | |
} | |
@Override | |
public Note save(Note note) { | |
if (getBaseObjectDAO().duplicateNoteExists(note)) { | |
throw new LIMSDuplicateRecordException("Duplicate record exists for " + note.getNoteType()); | |
} | |
return super.save(note); | |
} | |
@Override | |
public Note update(Note note) { | |
if (getBaseObjectDAO().duplicateNoteExists(note)) { | |
throw new LIMSDuplicateRecordException("Duplicate record exists for " + note.getNoteType()); | |
} | |
return super.update(note); | |
} | |
@Override | |
public boolean duplicateNoteExists(Note note) { | |
return getBaseObjectDAO().duplicateNoteExists(note); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Requests Requirements
Issue number if applicable.
documentation.
Summary
Added the note Service Tests
Screenshots
Related Issue
Add Intergration Service tests #1224
Other
@mozzy11 @mherman22 if this makes sense we could add more methods here