use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class DefaultMessageService method sendCompletenessMessage.
@Override
public int sendCompletenessMessage(CompleteDataSetRegistration registration) {
DataSet dataSet = registration.getDataSet();
if (dataSet == null) {
return 0;
}
UserGroup userGroup = dataSet.getNotificationRecipients();
User sender = currentUserService.getCurrentUser();
Set<User> recipients = new HashSet<>();
if (userGroup != null) {
recipients.addAll(new HashSet<>(userGroup.getMembers()));
}
if (dataSet.isNotifyCompletingUser()) {
recipients.add(sender);
}
if (recipients.isEmpty()) {
return 0;
}
String text = new VelocityManager().render(registration, COMPLETE_TEMPLATE);
MessageConversation conversation = new MessageConversation(COMPLETE_SUBJECT, sender, MessageType.SYSTEM);
conversation.addMessage(new Message(text, null, sender));
for (User user : recipients) {
conversation.addUserMessage(new UserMessage(user));
}
if (!conversation.getUserMessages().isEmpty()) {
int id = saveMessageConversation(conversation);
invokeMessageSenders(COMPLETE_SUBJECT, text, null, sender, new HashSet<>(conversation.getUsers()), false);
return id;
}
return 0;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testGetLockException.
@Test
public void testGetLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
LockException lockException = new LockException(period, orgUnit, dataSet);
dataSetService.addLockException(lockException);
String getUrl = "/lockExceptions?filter=organisationUnit.id:eq:" + orgUnit.getUid() + "&filter=period:eq:201612&filter=dataSet.id:eq:" + dataSet.getUid();
Lists.newArrayList(fieldWithPath("period").description("Property"), fieldWithPath("organisationUnit").description("Property"), fieldWithPath("dataSet").description("Property"));
mvc.perform(get(getUrl).session(session).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)).andDo(documentPrettyPrint("lockExceptions/get")).andReturn();
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testAddLockException.
@Test
public void testAddLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
String postUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
mvc.perform(post(postUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().is(201)).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("lockExceptions/add"));
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testDeleteLockException.
@Test
public void testDeleteLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
LockException lockException = new LockException(period, orgUnit, dataSet);
dataSetService.addLockException(lockException);
String deleteUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
mvc.perform(delete(deleteUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isNoContent()).andDo(documentPrettyPrint("lockExceptions/delete"));
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class DataEntryFormServiceTest method testGetDataEntryFormByName.
@Test
public void testGetDataEntryFormByName() {
DataSet dataSetA = createDataSet('A', periodType);
dataSetService.addDataSet(dataSetA);
DataEntryForm dataEntryForm = createDataEntryForm('A');
int id = dataEntryFormService.addDataEntryForm(dataEntryForm);
dataEntryForm = dataEntryFormService.getDataEntryForm(id);
assertEquals(dataEntryFormService.getDataEntryFormByName("DataEntryFormA"), dataEntryForm);
assertNull(dataEntryFormService.getDataEntryFormByName("DataEntryFormX"));
}
Aggregations