use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class PeriodUtil method getPeriod.
public static Period getPeriod(String periodName, PeriodType periodType) throws InvalidIdentifierReferenceException {
if (periodType instanceof DailyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof WeeklyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof MonthlyPeriodType) {
int dashIndex = periodName.indexOf('-');
if (dashIndex < 0) {
return null;
}
int month = Integer.parseInt(periodName.substring(0, dashIndex));
int year = Integer.parseInt(periodName.substring(dashIndex + 1, periodName.length()));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof YearlyPeriodType) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(periodName));
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof QuarterlyPeriodType) {
Calendar cal = Calendar.getInstance();
int month = 0;
if (periodName.substring(0, periodName.indexOf(" ")).equals("Jan")) {
month = 1;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Apr")) {
month = 4;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Jul")) {
month = 6;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Oct")) {
month = 10;
}
int year = Integer.parseInt(periodName.substring(periodName.lastIndexOf(" ") + 1));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
if (month != 0) {
return periodType.createPeriod(cal.getTime());
}
}
throw new InvalidIdentifierReferenceException("Couldn't make a period of type " + periodType.getName() + " and name " + periodName);
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method getPeriod.
public Period getPeriod(String periodName, PeriodType periodType) throws IllegalArgumentException {
if (periodType instanceof DailyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof WeeklyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof MonthlyPeriodType) {
int dashIndex = periodName.indexOf('-');
if (dashIndex < 0) {
return null;
}
int month = Integer.parseInt(periodName.substring(0, dashIndex));
int year = Integer.parseInt(periodName.substring(dashIndex + 1, periodName.length()));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof YearlyPeriodType) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(periodName));
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof QuarterlyPeriodType) {
Calendar cal = Calendar.getInstance();
int month = 0;
if (periodName.substring(0, periodName.indexOf(" ")).equals("Jan")) {
month = 1;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Apr")) {
month = 4;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Jul")) {
month = 6;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Oct")) {
month = 10;
}
int year = Integer.parseInt(periodName.substring(periodName.lastIndexOf(" ") + 1));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
if (month != 0) {
return periodType.createPeriod(cal.getTime());
}
}
throw new IllegalArgumentException("Couldn't make a period of type " + periodType.getName() + " and name " + periodName);
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
// ---------------------------------------------------------------------
// Add supporting data
// ---------------------------------------------------------------------
PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B', sourceA);
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
superUserService = getMockCurrentUserService("SuperUser", true, sourceA, UserAuthorityGroup.AUTHORITY_ALL);
userAService = getMockCurrentUserService("UserA", false, sourceA);
userBService = getMockCurrentUserService("UserB", false, sourceB);
userCService = getMockCurrentUserService("UserC", false, sourceB);
userDService = getMockCurrentUserService("UserD", false, sourceB);
userZ = createUser('Z');
userService.addUser(userZ);
UserGroup userGroupC = getUserGroup("UserGroupA", Sets.newHashSet(userCService.getCurrentUser()));
UserGroup userGroupD = getUserGroup("UserGroupB", Sets.newHashSet(userDService.getCurrentUser()));
optionA = new DataElementCategoryOption("CategoryOptionA");
optionB = new DataElementCategoryOption("CategoryOptionB");
categoryService.addDataElementCategoryOption(optionA);
categoryService.addDataElementCategoryOption(optionB);
categoryA = createDataElementCategory('A', optionA, optionB);
categoryService.addDataElementCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addDataElementCategoryCombo(categoryComboA);
optionComboA = createCategoryOptionCombo('A', categoryComboA, optionA);
optionComboB = createCategoryOptionCombo('B', categoryComboA, optionB);
optionComboC = createCategoryOptionCombo('C', categoryComboA, optionA, optionB);
categoryService.addDataElementCategoryOptionCombo(optionComboA);
categoryService.addDataElementCategoryOptionCombo(optionComboB);
categoryService.addDataElementCategoryOptionCombo(optionComboC);
optionGroupA = createCategoryOptionGroup('A', optionA);
optionGroupB = createCategoryOptionGroup('B', optionB);
categoryService.saveCategoryOptionGroup(optionGroupA);
categoryService.saveCategoryOptionGroup(optionGroupB);
optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
optionGroupSetB.addCategoryOptionGroup(optionGroupA);
optionGroupSetB.addCategoryOptionGroup(optionGroupB);
optionGroupA.getGroupSets().add(optionGroupSetB);
optionGroupB.getGroupSets().add(optionGroupSetB);
setPrivateAccess(optionA, userGroupC);
setPrivateAccess(optionB);
setPrivateAccess(optionGroupA);
setPrivateAccess(optionGroupB, userGroupD);
categoryService.updateCategoryOptionGroupSet(optionGroupSetB);
categoryService.updateCategoryOptionGroup(optionGroupA);
categoryService.updateCategoryOptionGroup(optionGroupB);
userCService.getCurrentUser().getUserCredentials().getCatDimensionConstraints().add(categoryA);
userDService.getCurrentUser().getUserCredentials().getCogsDimensionConstraints().add(optionGroupSetB);
dateA = getDate(2017, 1, 1);
dateB = getDate(2018, 1, 1);
level1 = new DataApprovalLevel("01", 1, null);
level2 = new DataApprovalLevel("02", 2, null);
level3 = new DataApprovalLevel("03", 2, optionGroupSetB);
dataApprovalLevelService.addDataApprovalLevel(level1);
dataApprovalLevelService.addDataApprovalLevel(level2);
dataApprovalLevelService.addDataApprovalLevel(level3);
workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2, level3));
dataApprovalService.addWorkflow(workflowA);
dataApprovalService.addWorkflow(workflowB);
DataApproval approvalAA1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userZ);
DataApproval approvalAB1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboB, false, dateA, userZ);
DataApproval approvalAC1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboC, false, dateA, userZ);
DataApproval approvalBA2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
DataApproval approvalBA3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
auditAA1 = new DataApprovalAudit(approvalAA1, APPROVE);
auditAB1 = new DataApprovalAudit(approvalAB1, UNAPPROVE);
auditAC1 = new DataApprovalAudit(approvalAC1, ACCEPT);
auditBA2 = new DataApprovalAudit(approvalBA2, UNACCEPT);
auditBB2 = new DataApprovalAudit(approvalBB2, APPROVE);
auditBC2 = new DataApprovalAudit(approvalBC2, UNAPPROVE);
auditBA3 = new DataApprovalAudit(approvalBA3, ACCEPT);
auditBB3 = new DataApprovalAudit(approvalBB3, UNACCEPT);
auditBC3 = new DataApprovalAudit(approvalBC3, APPROVE);
dataApprovalAuditStore.save(auditAA1);
dataApprovalAuditStore.save(auditAB1);
dataApprovalAuditStore.save(auditAC1);
dataApprovalAuditStore.save(auditBA2);
dataApprovalAuditStore.save(auditBB2);
dataApprovalAuditStore.save(auditBC2);
dataApprovalAuditStore.save(auditBA3);
dataApprovalAuditStore.save(auditBB3);
dataApprovalAuditStore.save(auditBC3);
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class UniqueArrayListTest method testCollectionConstructor.
@Test
public void testCollectionConstructor() {
List<Period> list = new ArrayList<>();
PeriodType periodType = new MonthlyPeriodType();
Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
// Duplicate
Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
list.add(peA);
list.add(peB);
list.add(peC);
assertEquals(3, list.size());
List<Period> uniqueList = new UniqueArrayList<>(list);
assertEquals(2, uniqueList.size());
assertTrue(uniqueList.contains(peA));
assertTrue(uniqueList.contains(peB));
assertTrue(uniqueList.contains(peC));
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class ReportController method getReport.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getReport(HttpServletRequest request, HttpServletResponse response, String uid, String organisationUnitUid, String isoPeriod, Date date, String type, String contentType, boolean attachment) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
if (organisationUnitUid == null && report.hasReportTable() && report.getReportTable().hasReportParams() && report.getReportTable().getReportParams().isOrganisationUnitSet()) {
organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
}
if (report.isTypeHtml()) {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, report.getCacheStrategy());
reportService.renderHtmlReport(response.getWriter(), uid, date, organisationUnitUid);
} else {
date = date != null ? date : new DateTime().minusMonths(1).toDate();
Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString(isoPeriod) : new MonthlyPeriodType().createPeriod(date);
String filename = CodecUtils.filenameEncode(report.getName()) + "." + type;
contextUtils.configureResponse(response, contentType, report.getCacheStrategy(), filename, attachment);
JasperPrint print = reportService.renderReport(response.getOutputStream(), uid, period, organisationUnitUid, type);
if ("html".equals(type)) {
request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
}
}
}
Aggregations