Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 15, 2021 07:55
Show Gist options
  • Save aspose-com-gists/472405ac9bab4502a485ee007b92074c to your computer and use it in GitHub Desktop.
Save aspose-com-gists/472405ac9bab4502a485ee007b92074c to your computer and use it in GitHub Desktop.
Aspose.Tasks for Java
This Gist contains code snippets from examples of Aspose.Tasks for Java.
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
Project project = new Project(dataDir + "input.mpp");
// Remove an exception
Calendar cal = project.getCalendars().toList().get(0);
if (cal.getExceptions().getCount() > 1) {
CalendarException exc = cal.getExceptions().toList().get(0);
cal.getExceptions().remove(exc);
}
// Add an exception
CalendarException calExc = new CalendarException();
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 1, 1, 0, 0, 0);
calExc.setFromDate(calObject.getTime());
calObject.set(2009, 1, 3, 0, 0, 0);
calExc.setToDate(calObject.getTime());
cal.getExceptions().add(calExc);
// Display exceptions
for (CalendarException calExc1 : cal.getExceptions()) {
System.out.println("From" + calExc1.getFromDate().toString());
System.out.println("To" + calExc1.getToDate().toString());
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
Project project = new Project(dataDir + "input.mpp");
//Remove an exception
Calendar cal = project.getCalendars().toList().get(0);
if (cal.getExceptions().size() > 1)
{
CalendarException exc = cal.getExceptions().toList().get(0);
cal.getExceptions().remove(exc);
}
//Add an exception
CalendarException calExc = new CalendarException();
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 1, 1, 0, 0, 0);
calExc.setFromDate(calObject.getTime());
calObject.set(2009, 1, 3, 0, 0, 0);
calExc.setToDate(calObject.getTime());
cal.getExceptions().add(calExc);
//Display exceptions
for(CalendarException calExc1:cal.getExceptions())
{
System.out.println("From" + calExc1.getFromDate().toString());
System.out.println("To" + calExc1.getToDate().toString());
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdaysForExceptions.class);
//Create a project instance
Project project = new Project();
//Define Calendar
Calendar cal = project.getCalendars().add("Calendar1");
//Define week days exception for Christmas
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(false);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 12, 24, 0, 0, 0);
except.setFromDate(calObject.getTime());
calObject.set(2009, 12, 31, 23, 59, 0);
except.setToDate(calObject.getTime());
except.setType(CalendarExceptionType.Daily);
except.setDayWorking(false);
cal.getExceptions().add(except);
//Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdaysForExceptions.class);
// Create a project instance
Project project = new Project();
// Define Calendar
Calendar cal = project.getCalendars().add("Calendar1");
// Define week days exception for Christmas
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(false);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 12, 24, 0, 0, 0);
except.setFromDate(calObject.getTime());
calObject.set(2009, 12, 31, 23, 59, 0);
except.setToDate(calObject.getTime());
except.setType(CalendarExceptionType.Daily);
except.setDayWorking(false);
cal.getExceptions().add(except);
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(true);
except.setOccurrences(5);
except.setType(CalendarExceptionType.YearlyByDay);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HandleOccurrences.class);
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(true);
except.setOccurrences(5);
except.setType(CalendarExceptionType.YearlyByDay);
// The path to the documents directory.
String dataDir = Utils.getDataDir(RetrieveCalendarExceptions.class);
Project project = new Project(dataDir + "file.mpp");
for(Calendar cal:project.getCalendars())
{
for(CalendarException calExc: cal.getExceptions())
{
System.out.println("From: " + calExc.getFromDate().toString()) ;
System.out.println("To: " + calExc.getToDate().toString()) ;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RetrieveCalendarExceptions.class);
Project project = new Project(dataDir + "file.mpp");
for (Calendar cal : project.getCalendars()) {
for (CalendarException calExc : cal.getExceptions()) {
System.out.println("From: " + calExc.getFromDate().toString());
System.out.println("To: " + calExc.getToDate().toString());
}
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(CalendarProperties.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "prj.mpp");
for (Calendar cal : project.getCalendars()) {
if (cal.getName().toString() != null) {
for (WeekDay wd : cal.getWeekDays()) {
double ts = wd.getWorkingTime();
double time = ts / (OneHour);
System.out.println("Day Type" + wd.getDayType() + "Hours" + ts);
}
System.out.println("Base Calendar : ");
if (cal.isBaseCalendar())
System.out.println("Self");
else
System.out.println(cal.getBaseCalendar().getName());
System.out.println("UID : " + cal.getUid());
System.out.println("Name : " + cal.getName());
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CalendarProperties.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "prj.mpp");
for (Calendar cal : project.getCalendars()) {
if (cal.getName().toString() != null) {
for (WeekDay wd : cal.getWeekDays()) {
double ts = wd.getWorkingTime();
double time = ts / (OneHour);
System.out.println("Day Type" + wd.getDayType() + "Hours" + ts);
}
System.out.println("Base Calendar : ");
if (cal.isBaseCalendar())
System.out.println("Self");
else
System.out.println(cal.getBaseCalendar().getName());
System.out.println("UID : " + cal.getUid());
System.out.println("Name : " + cal.getName());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateCalendar.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal1 = prj.getCalendars().add("no info");
Calendar cal2 = prj.getCalendars().add("no name");
Calendar cal3 = prj.getCalendars().add("cal3");
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateCalendar.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal1 = prj.getCalendars().add("no info");
Calendar cal2 = prj.getCalendars().add("no name");
Calendar cal3 = prj.getCalendars().add("cal3");
prj.getCalendars().add(cal1);
prj.getCalendars().add(cal2);
prj.getCalendars().add(cal3);
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdays.class);
//Create a project instance
Project prj = new Project();
//Define Calendar
Calendar cal = prj.getCalendars().add("Calendar1");
//Add working days Monday through Thursday with default timings
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Thursday));
cal.getWeekDays().add(new WeekDay(DayType.Saturday));
cal.getWeekDays().add(new WeekDay(DayType.Sunday));
//Set Friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
//Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
java.util.Calendar calTime = java.util.Calendar.getInstance();
calTime.set(1,1,1,9,0,0);
Date date = calTime.getTime();
wt1.setFromTime(date);
calTime.set(1,1,1,12,0,0);
date = calTime.getTime();
wt1.setToTime(date);
WorkingTime wt2 = new WorkingTime();
calTime.set(1,1,1,13,0,0);
date = calTime.getTime();
wt2.setFromTime(date);
calTime.set(1,1,1,16,0,0);
date = calTime.getTime();
wt2.setToTime(date);
myWeekDay.getWorkingTimes().add(wt1);
myWeekDay.getWorkingTimes().add(wt2);
myWeekDay.setDayWorking(true);
cal.getWeekDays().add(myWeekDay);
//Save the Project
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdays.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal = prj.getCalendars().add("Calendar1");
// Add working days monday through thursday with default timings
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Thursday));
cal.getWeekDays().add(new WeekDay(DayType.Saturday));
cal.getWeekDays().add(new WeekDay(DayType.Sunday));
// Set friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
// Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
java.util.Calendar calTime = java.util.Calendar.getInstance();
calTime.set(1, 1, 1, 9, 0, 0);
Date date = calTime.getTime();
wt1.setFromTime(date);
calTime.set(1, 1, 1, 12, 0, 0);
date = calTime.getTime();
wt1.setToTime(date);
WorkingTime wt2 = new WorkingTime();
calTime.set(1, 1, 1, 13, 0, 0);
date = calTime.getTime();
wt2.setFromTime(date);
calTime.set(1, 1, 1, 16, 0, 0);
date = calTime.getTime();
wt2.setToTime(date);
myWeekDay.getWorkingTimes().add(wt1);
myWeekDay.getWorkingTimes().add(wt2);
myWeekDay.setDayWorking(true);
cal.getWeekDays().add(myWeekDay);
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetWorkingHours.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "BaselineTask.mpp");
Task task = project.getRootTask().getChildren().getById(1);
Calendar taskCalendar = task.get(Tsk.CALENDAR);
java.util.Calendar calStartDate = java.util.Calendar.getInstance();
calStartDate.setTime(task.get(Tsk.START));
java.util.Calendar calEndDate = java.util.Calendar.getInstance();
calEndDate.setTime(task.get(Tsk.FINISH));
java.util.Calendar tempDate = java.util.Calendar.getInstance();
tempDate = calStartDate;
Resource resource = project.getResources().getById(1);
Calendar resourceCalendar = resource.get(Rsc.CALENDAR);
// TimeSpan timeSpan;
long timeSpan = 0;
// Get Duration in Minutes
double durationInMins = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInMins = durationInMins + (timeSpan / OneMin);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
// Get Duration in Hours
double durationInHours = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInHours = durationInHours + (timeSpan / OneHour);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
// Get Duration in Days
double durationInDays = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
if ((timeSpan / OneHour) > 0)
durationInDays = durationInDays + (timeSpan / OneHour / 8.0);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate = calStartDate;
System.out.println("Duration in Minutes = " + durationInMins);
System.out.println("Duration in Hours = " + durationInHours);
System.out.println("Duration in Days = " + durationInDays);
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetWorkingHours.class);
long OneSec = 10000000;//microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "BaselineTask.mpp");
Task task = project.getRootTask().getChildren().getById(1);
Calendar taskCalendar = task.get(Tsk.CALENDAR);
java.util.Calendar calStartDate = java.util.Calendar.getInstance();
calStartDate.setTime(task.get(Tsk.START));
java.util.Calendar calEndDate = java.util.Calendar.getInstance();
calEndDate.setTime(task.get(Tsk.FINISH));
java.util.Calendar tempDate = java.util.Calendar.getInstance();
tempDate = calStartDate;
Resource resource = project.getResources().getById(1);
Calendar resourceCalendar = resource.get(Rsc.CALENDAR);
//TimeSpan timeSpan;
long timeSpan = 0;
//Get Duration in Minutes
double durationInMins = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInMins = durationInMins + (timeSpan / OneMin);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
//Get Duration in Hours
double durationInHours = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInHours = durationInHours + (timeSpan / OneHour);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
//Get Duration in Days
double durationInDays = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
if ((timeSpan / OneHour) > 0)
durationInDays = durationInDays + (timeSpan/OneHour/8.0);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate = calStartDate;
System.out.println("Duration in Minutes = " + durationInMins);
System.out.println("Duration in Hours = " + durationInHours);
System.out.println("Duration in Days = " + durationInDays);
System.out.println();
// The path to the documents directory.
String dataDir = Utils.getDataDir(MakeStandardCalendar.class);
//Create a project instance
Project project = new Project();
//Define Calendar and make it standard
Calendar cal1 = project.getCalendars().add("My Cal");
Calendar.makeStandardCalendar(cal1);
//Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(MakeStandardCalendar.class);
// Create a project instance
Project project = new Project();
// Define Calendar and make it standard
Calendar cal1 = project.getCalendars().add("My Cal");
Calendar.makeStandardCalendar(cal1);
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReadWorkWeeks.class);
// Create project instance and access calendar and work weeks collection
Project project = new Project(dataDir + "ReadWorkWeeksInformation.mpp");
Calendar calendar = project.getCalendars().getByUid(3);
WorkWeekCollection collection = calendar.getWorkWeeks();
for (WorkWeek workWeek : collection) {
// Display work week name, from and to dates
System.out.println(workWeek.getName());
System.out.println(workWeek.getFromDate());
System.out.println(workWeek.getToDate());
// This data is all about "Details." button you can set special working times
// for special WeekDay or even make it non-working
WeekDayCollection weekDays = workWeek.getWeekDays();
for (WeekDay day : weekDays) {
// You can further traverse through working times and display these
WorkingTimeCollection workingTimes = day.getWorkingTimes();
}
}
private static void GetTestCalendar(Calendar cal)
{
Calendar.makeStandardCalendar(cal);
cal.setName("Test calendar");
CalendarException exc = new CalendarException();
Date curTime = java.util.Calendar.getInstance().getTime();
exc.setFromDate(curTime);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.add(java.util.Calendar.DATE, 2);
exc.setToDate(calObject.getTime());
exc.setDayWorking(true);
WorkingTime wt1 = new WorkingTime();
calObject.set(1,1,1, 9,0,0);
wt1.setFromTime(calObject.getTime());
calObject.set(1,1,1, 13,0,0);
wt1.setToTime(calObject.getTime());
WorkingTime wt2 = new WorkingTime();
calObject.set(1, 1, 1, 14, 0, 0);
wt2.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 19, 0, 0);
wt2.setToTime(calObject.getTime());
WorkingTime wt3 = new WorkingTime();
calObject.set(10, 1, 1, 20, 0, 0);
wt3.setFromTime(calObject.getTime());
calObject.set(10, 1, 1, 21, 0, 0);
wt3.setToTime(calObject.getTime());
exc.getWorkingTimes().add(wt1);
exc.getWorkingTimes().add(wt2);
exc.getWorkingTimes().add(wt3);
cal.getExceptions().add(exc);
CalendarException exc2 = new CalendarException();
java.util.Calendar newCal = java.util.Calendar.getInstance();
newCal.add(java.util.Calendar.DATE, 7);
exc2.setFromDate(newCal.getTime());
exc2.setToDate(exc2.getFromDate());
exc2.setDayWorking(false);
cal.getExceptions().add(exc2);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Calendar.makeStandardCalendar(cal);
cal.setName("Test calendar");
CalendarException exc = new CalendarException();
Date curTime = java.util.Calendar.getInstance().getTime();
exc.setFromDate(curTime);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.add(java.util.Calendar.DATE, 2);
exc.setToDate(calObject.getTime());
exc.setDayWorking(true);
WorkingTime wt1 = new WorkingTime();
calObject.set(1, 1, 1, 9, 0, 0);
wt1.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 13, 0, 0);
wt1.setToTime(calObject.getTime());
WorkingTime wt2 = new WorkingTime();
calObject.set(1, 1, 1, 14, 0, 0);
wt2.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 19, 0, 0);
wt2.setToTime(calObject.getTime());
WorkingTime wt3 = new WorkingTime();
calObject.set(10, 1, 1, 20, 0, 0);
wt3.setFromTime(calObject.getTime());
calObject.set(10, 1, 1, 21, 0, 0);
wt3.setToTime(calObject.getTime());
exc.getWorkingTimes().add(wt1);
exc.getWorkingTimes().add(wt2);
exc.getWorkingTimes().add(wt3);
cal.getExceptions().add(exc);
CalendarException exc2 = new CalendarException();
java.util.Calendar newCal = java.util.Calendar.getInstance();
newCal.add(java.util.Calendar.DATE, 7);
exc2.setFromDate(newCal.getTime());
exc2.setToDate(exc2.getFromDate());
exc2.setDayWorking(false);
cal.getExceptions().add(exc2);
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatedCalendarToMpp.class);
String resultFile = "OutputMPP.mpp";
String newFile = "SampleMPP.mpp";
Project project = new Project(dataDir + newFile);
Calendar cal1 = project.getCalendars().add("Calendar 1");
GetTestCalendar(cal1);
project.set(Prj.CALENDAR, cal1);
//Save the Project
project.save(dataDir + resultFile, SaveFileFormat.MPP);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyCodes.class);
Project prj = new Project(dataDir + "project5.mpp");
System.out.println(prj.get(Prj.CURRENCY_CODE));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyCodes.class);
Project prj = new Project();
prj.set(Prj.CURRENCY_CODE, "USD");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyDigits.class);
Project project = new Project(dataDir + "project5.mpp");
System.out.println(project.get(Prj.CURRENCY_DIGITS));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyDigits.class);
Project project = new Project();
project.set(Prj.CURRENCY_DIGITS, 2);
project.save(dataDir + "ProjectCurrDigits.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencySymbols.class);
Project project = new Project(dataDir + "project5.mpp");
System.out.println(project.get(Prj.CURRENCY_SYMBOL));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencySymbols.class);
Project project = new Project();
project.set(Prj.CURRENCY_SYMBOL, "$$");
Project project = CreateTestProjectWithCustomField();
Task task = project.getRootTask().getChildren().getById(1);
ExtendedAttributeDefinition numberDefinition = ExtendedAttributeDefinition.createTaskDefinition(ExtendedAttributeTask.Number1, null);
project.getExtendedAttributes().add(numberDefinition);
ExtendedAttribute numberAttribute = numberDefinition.createExtendedAttribute();
task.getExtendedAttributes().add(numberAttribute);
// Set ProjDateDiff formula and print extended attribute value
numberDefinition.setFormula("ProjDateDiff(\"03/23/2015\",\"03/18/2015\")");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
numberDefinition.setFormula("ProjDateDiff(\"03/23/2015\",\"03/25/2015\")");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
ExtendedAttributeDefinition dateDefinition = ExtendedAttributeDefinition.createTaskDefinition(ExtendedAttributeTask.Date1, null);
project.getExtendedAttributes().add(dateDefinition);
ExtendedAttribute dateAttribute = dateDefinition.createExtendedAttribute();
task.getExtendedAttributes().add(dateAttribute);
ExtendedAttributeDefinition durationDefinition = ExtendedAttributeDefinition.createTaskDefinition(ExtendedAttributeTask.Duration4, "Custom duration field");
project.getExtendedAttributes().add(durationDefinition);
ExtendedAttribute durationAttribute = durationDefinition.createExtendedAttribute();
task.getExtendedAttributes().add(durationAttribute);
ExtendedAttributeDefinition textDefinition = ExtendedAttributeDefinition.createTaskDefinition(ExtendedAttributeTask.Text5, "Custom text field");
project.getExtendedAttributes().add(textDefinition);
ExtendedAttribute textAttribute = textDefinition.createExtendedAttribute();
task.getExtendedAttributes().add(textAttribute);
// Set ProjDateSub formula and print extended attribute value
dateDefinition.setFormula("ProjDateSub(\"3/19/2015\", \"1d\")");
System.out.println(dateAttribute.getDateValue());
// We can set ProjDurConv formula to duration-valued attribute as well as to text-valued attribute.
// Set ProjDurConv formula to duration-valued extended attribute and print its value.
durationDefinition.setFormula("ProjDurConv([Duration], pjHours)");
System.out.println(durationAttribute.getDurationValue());
// Set ProjDurConv formula to text-valued extended attribute and print its value.
textDefinition.setFormula("ProjDurConv([Duration], pjHours)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
textDefinition.setFormula("ProjDurConv([Duration], pjWeeks)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
// Set Second formula and print entended attribute value
numberDefinition.setFormula("Second(\"4/21/2015 2:53:41 AM\")");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
// Set Weekday formula and print entended attribute value
numberDefinition.setFormula("Weekday(\"24/3/2015\", 1)");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
numberDefinition.setFormula("Weekday(\"24/3/2015\", 2)");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
numberDefinition.setFormula("Weekday(\"24/3/2015\", 3)");
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
public static void EvaluateChoose()
{
Project project = CreateTestProjectWithCustomField();
// Set Formula
project.getExtendedAttributes().get(0).setFormula("Choose(3, \"This is a\", \"right\", \"choice\")");
// Print extended attribute value
Task task = project.getRootTask().getChildren().getById(1);
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
}
public static void EvaluateIsNumeric()
{
String[] numericFormulas = { "IsNumeric('AAA')", "IsNUmeric(1)", "IsNumeric(1<0)", "IsNumeric(\"1.1\")", "IsNumeric(Choose((2 + Sgn(2^-3)), 123, \"one two three\"))" };
Project project = CreateTestProjectWithCustomField();
for (String numericFormula : numericFormulas)
{
// Set Formula
project.getExtendedAttributes().get(0).setFormula(numericFormula);
// Print extended attribute value
Task task = project.getRootTask().getChildren().getById(1);
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
}
}
public static void EvaluateSwitch()
{
Project project = CreateTestProjectWithCustomField();
// Set Formula
project.getExtendedAttributes().get(0).setFormula("Switch( 0 < 1, \"0 is lesser than 1\", 0 > 1, \"0 is greater than 1\")");
// Print extended attribute value
Task task = project.getRootTask().getChildren().getById(1);
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
}
Project project = CreateTestProjectWithCustomField();
// Set formula Sin(pi/2)
project.getExtendedAttributes().get(0).setFormula("Sin(3.1415926/2)");
// Print Calculated value
Task task = project.getRootTask().getChildren().getById(1);
System.out.println("Sin(pi/2): {0}" + task.getExtendedAttributes().get(0).getNumericValue());
Project project = CreateTestProjectWithCustomField();
Task task = project.getRootTask().getChildren().getById(1);
// EvaluateStrConv
// Set formulas and print extended attribute value
project.getExtendedAttributes().get(0).setFormula("StrConv(\"sTring and sTRINg\",3)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
project.getExtendedAttributes().get(0).setFormula("StrConv(\"sTring and sTRINg\",1)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
project.getExtendedAttributes().get(0).setFormula("StrConv(\"sTring and sTRINg\",2)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
// EvaluateStringFunction
// Set formulas and print extended attribute value
project.getExtendedAttributes().get(0).setFormula("String(5, 40)");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
project.getExtendedAttributes().get(0).setFormula("String(5, \"A\")");
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
project.getExtendedAttributes().get(0).setFormula("String(-5, \"A\")");
// #Error
System.out.println(task.getExtendedAttributes().get(0).getTextValue());
// Create new project instance
Project project = new Project();
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2015, 26, 3, 8,0,0);
project.set(Prj.START_DATE, cal.getTime());
// Add new task with extended attribute
Task task = project.getRootTask().getChildren().add("Task");
ExtendedAttributeDefinition extendedAttributeDefinition = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text5, "My Ext Attr");
project.getExtendedAttributes().add(extendedAttributeDefinition);
ExtendedAttribute extendedAttribute = extendedAttributeDefinition.createExtendedAttribute();
task.getExtendedAttributes().add(extendedAttribute);
// Add resource and resource assignment
Resource rsc = project.getResources().add("Rsc");
ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
return project;
Project project = CreateTestProjectWithCustomField();
// Set formula for extended attribute
project.getExtendedAttributes().get(0).setFormula("[Critical]-[Marked]+4+[Active]-Not [Active]");
// Print value of extened attribute
Task task = project.getRootTask().getChildren().getById(1);
System.out.println("Formula with boolean values" + task.getExtendedAttributes().get(0).getTextValue());
Project project = CreateTestProjectWithCustomField();
// Set formula for extended attribute
project.getExtendedAttributes().get(0).setFormula("\"Total tasks: \" & [Task Count] & \" Total resources: \" & [Resource Count]");
// Print value of extened attribute
Task task = project.getRootTask().getChildren().getById(1);
System.out.println("Formula with boolean values" + task.getExtendedAttributes().get(0).getTextValue());
// see this helper method below
Project project = CreateTestProjectWithCustomField();
ExtendedAttributeDefinition attr = project.getExtendedAttributes().get(0);
attr.setAlias("Days from finish to deadline");
attr.setFormula("[Deadline] - [Finish]");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2015, 26, 3, 8,0,0);
Task task = project.getRootTask().getChildren().getById(1);
task.set(Tsk.DEADLINE, cal.getTime());
project.save("SaveFile.mpp", SaveFileFormat.MPP);
Project project = CreateTestProjectWithCustomField();
// Set arithmetic formula for extended attribute
ExtendedAttributeDefinition attr = project.getExtendedAttributes().get(0);
attr.setAlias("Arithmetic Expression");
attr.setFormula("(1+3*(2+ -5)+8/2)^3");
// Display extended attribute value
Task task = project.getRootTask().getChildren().getById(1);
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
Project project = CreateTestProjectWithCustomField();
// Set Formula
ExtendedAttributeDefinition attr = project.getExtendedAttributes().get(0);
attr.setAlias("Task number fields");
attr.setFormula("(([Outline Level] + [Priority] + [% Complete])/2");
Task task = project.getRootTask().getChildren().getById(1);
// Print extended attribute value before and after updating task percent complete
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
task.set(Tsk.PERCENT_COMPLETE, 50);
System.out.println(task.getExtendedAttributes().get(0).getNumericValue());
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project proj = new Project(dataDir + "FormulaField.mpp"); // attached test mpp
ExtendedAttributeDefinition attr = proj.getExtendedAttributes().get(0);
System.out.println("Attribute Formula: " + attr.getFormula());
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project project = new Project();
ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Cost,
ExtendedAttributeTask.Cost1, "");
attribute.setFormula("[Cost]-[Actual Cost]");
project.getExtendedAttributes().add(attribute);
// Add task
Task task = project.getRootTask().getChildren().add("Task");
// Create extended attribute
ExtendedAttribute extendedAttribute = attribute.createExtendedAttribute();
task.getExtendedAttributes().add(extendedAttribute);
// Display if extended attributes are read only or not
System.out.println(
extendedAttribute.getValueReadOnly() == true ? "Value is Read only" : "Value is not read only");
extendedAttribute.setTextValue("-36755");
System.out.println(
extendedAttribute.getTextValue() == " " ? "Formula values are read-only" : "Values are not read-only");
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project project = new Project(dataDir + "New project 2010.mpp");
project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));
// create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Text,
ExtendedAttributeTask.Text1, "Custom");
attr.setAlias("Double Costs");
attr.setFormula("[Cost]*2");
project.getExtendedAttributes().add(attr);
// add a task to see the result in MSP
Task task = project.getRootTask().getChildren().add("Task");
// set task cost
task.set(Tsk.COST, BigDecimal.valueOf(100));
// see the result in the attached screenshot (result.jpg)
project.save(dataDir + "saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HandleExceptions.class);
Project project;
try {
project = new Project(dataDir + "ProjectWithException.mpp");
} catch (TasksReadingException ex) {
System.out.println("Message:");
System.out.println(ex.getMessage());
System.out.println("Log:");
System.out.println(ex.getLogText());
if (ex.getCause() != null) {
System.out.println("Inner exception message:");
System.out.println(ex.getCause().getMessage());
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
String dataDir = Utils.getDataDir(ReportingServices.class);
// Project OverView
Project project3 = new Project(dataDir + "Cyclic stucture.mpp");
project3.saveReport(dataDir + "ProjectOverView.pdf", ReportType.ProjectOverview);
// Resource Cost Overview
Project project4 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project4.saveReport(dataDir + "ResourceCostOverview.pdf", ReportType.ResourceCostOverview);
// Cost Overview
Project project5 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project5.saveReport(dataDir + "CostOverview.pdf", ReportType.CostOverview);
// Work Overview
Project project6 = new Project(dataDir + "Residential Construction.mpp");
project6.saveReport(dataDir + "WorkOverview.pdf", ReportType.WorkOverview);
// Critical Tasks
Project project7 = new Project(dataDir + "Residential Construction.mpp");
project7.saveReport(dataDir + "CriticalTasks.pdf", ReportType.CriticalTasks);
// Milestones
Project project8 = new Project(dataDir + "Residential Construction.mpp");
project8.saveReport(dataDir + "Milestones.pdf", ReportType.Milestones);
// Late Tasks
Project project9 = new Project(dataDir + "Residential Construction.mpp");
project9.saveReport(dataDir + "LateTasks.pdf", ReportType.LateTasks);
// Resource Overview
Project project10 = new Project(dataDir + "Software Development Plan.mpp");
project10.saveReport(dataDir + "ResourceOverview.pdf", ReportType.ResourceOverview);
// Cost Overruns
Project project11 = new Project(dataDir + "Software Development.mpp");
project11.saveReport(dataDir + "CostOverruns.pdf", ReportType.CostOverruns);
// Upcoming Task
Project project12 = new Project(dataDir + "UpcomingTasks.mpp");
project12.saveReport(dataDir + "UpcomingTasks.pdf", ReportType.UpcomingTask);
// Task Cost Overview
Project project13 = new Project(dataDir + "Software Development.mpp");
project13.saveReport(dataDir + "TaskCostOverview.pdf", ReportType.TaskCostOverview);
// Over allocated Resources
Project project14 = new Project(dataDir + "Software Development Plan.mpp");
project14.saveReport(dataDir + "OverAllocatedResources.pdf", ReportType.OverallocatedResources);
// Slipping Tasks
Project project15 = new Project(dataDir + "Cyclic stucture.mpp");
project15.saveReport(dataDir + "SlippingTasks.pdf", ReportType.SlippingTasks);
// Best Practice Analyzer
Project project16 = new Project(dataDir + "Cyclic stucture.mpp");
project16.saveReport(dataDir + "BestPracticeAnalyzer.pdf", ReportType.BestPracticeAnalyzer);
// Burn down
Project project17 = new Project(dataDir + "Cyclic stucture.mpp");
project17.saveReport(dataDir + "Burndown.pdf", ReportType.Burndown);
// Cash Flow
Project project18 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project18.saveReport(dataDir + "CashFlow.pdf", ReportType.CashFlow);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
RiskAnalyzer analyzer= new RiskAnalyzer(settings);
RiskAnalysisResult analysisResult = analyzer.analyze(project);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Project project = new Project("NewProductDev.mpp"); // attached test project
// Initialize a risk pattern
Task task = project.getRootTask().getChildren().getById(14);
RiskPattern pattern = new RiskPattern(task);
// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
// note that the normal distributions are often used in the natural and social sciences to represent real-valued random variables whose distributions are not known,
// thus this distribution is set to default (for more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
pattern.setDistribution (ProbabilityDistributionType.Normal);
// Set the percentage of the most likely task duration which can happen in the best possible project scenario
// (the default value is 75, which means that if the estimated specified task duration is 4 days then the optimistic duration will be 3 days)
pattern.setOptimistic(70);
// Set the percentage of the most likely task duration which can happen in the worst possible project scenario
// (the defaut value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.).
pattern.setPessimistic(130);
// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
// You can think of it as a value of standard deviation: the more uncertain about your estimates you are, the more the value of standard deviation used in random number generator is
pattern.setConfidenceLevel(ConfidenceLevel.CL75);
// you can add as many risk patterns as needed to model expected project risks
settings.getPatterns().add(pattern);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
RiskAnalysisSettings settings = new RiskAnalysisSettings();
// set a number of iterations for Monte Carlo simulation (the default value is 100).
settings.setIterationsCount(200);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
//Select the desired output (here we get early finish of the root task)
RiskItemStatistics rootEarlyFinish = analysisResult.getRiskItems(RiskItemType.EarlyFinish).get(project.getRootTask());
System.out.println("Expected value: "+ rootEarlyFinish.getExpectedValue());
System.out.println("StandardDeviation: " + rootEarlyFinish.getStandardDeviation());
System.out.println("10% Percentile: " +rootEarlyFinish.getPercentile(10));
System.out.println("50% Percentile: " + rootEarlyFinish.getPercentile(50));
System.out.println("90% Percentile: " + rootEarlyFinish.getPercentile(90));
System.out.println("Minimum: " + rootEarlyFinish.getMinimum());
System.out.println("Maximum: " + rootEarlyFinish.getMaximum());
// Also pdf report can be saved (it is rendered for Project Root Task Finish date):
analysisResult.saveReport("AnalysisReport.pdf");
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteMetadata.class);
long OneSec = 10000000;
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
long OneDayEightHour = 8 * OneHour;
long OneDayTwentyFourHour = 24 * OneHour;
Project project = new Project(dataDir + "New project 2010.mpp");
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2012, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2013, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date toDate = calendar.getTime();
WorkingTime wt = new WorkingTime();
wt.setFromTime(startDate);
wt.setToTime(toDate);
WeekDay day = project.get(Prj.CALENDAR).getWeekDays().toList().get(1);
day.getWorkingTimes().add(wt);
project.get(Prj.CALENDAR).setName("CHANGED NAME!");
Task task = project.getRootTask().getChildren().add("Task 1");
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task.set(Tsk.DURATION, project.getDuration(3));
task.set(Tsk.CONTACT, "Rsc 1");
// new fields
task.set(Tsk.IS_MARKED, true);
task.set(Tsk.IGNORE_WARNINGS, true);
Task task2 = project.getRootTask().getChildren().add("Task 2");
task2.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task2.set(Tsk.CONTACT, "Rsc 2");
project.getTaskLinks().add(task, task2, TaskLinkType.FinishToStart, project.getDuration(-1, TimeUnitType.Day));
calendar.set(2013, java.util.Calendar.DECEMBER, 13, 9, 0, 0);
startDate = calendar.getTime();
project.set(Prj.START_DATE, startDate);
Resource rsc = project.getResources().add("Rsc 1");
rsc.set(Rsc.TYPE, ResourceType.Work);
rsc.set(Rsc.INITIALS, "WR");
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.Prorated);
rsc.set(Rsc.MAX_UNITS, 1d);
rsc.set(Rsc.CODE, "Code 1");
rsc.set(Rsc.GROUP, "Workers");
rsc.set(Rsc.E_MAIL_ADDRESS, "1@gmail.com");
rsc.set(Rsc.WINDOWS_USER_ACCOUNT, "user_acc1");
rsc.set(Rsc.IS_GENERIC, new NullableBool(true));
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.End);
rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(10));
rsc.set(Rsc.STANDARD_RATE_FORMAT, RateFormatType.Day);
rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(15));
rsc.set(Rsc.OVERTIME_RATE_FORMAT, RateFormatType.Hour);
rsc.set(Rsc.IS_TEAM_ASSIGNMENT_POOL, true);
rsc.set(Rsc.COST_CENTER, "Cost Center 1");
ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
assn.set(Asn.UID, 1);
assn.set(Asn.WORK, task.get(Tsk.DURATION));
assn.set(Asn.REMAINING_WORK, assn.get(Asn.WORK));
assn.set(Asn.REGULAR_WORK, assn.get(Asn.WORK));
task.set(Tsk.WORK, assn.get(Asn.WORK));
rsc.set(Rsc.WORK, task.get(Tsk.WORK));
assn.set(Asn.START, task.get(Tsk.START));
assn.set(Asn.FINISH, task.get(Tsk.FINISH));
// Add extended attribute for project and task
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Flag,
ExtendedAttributeTask.Flag1, "My Flag Field");
project.getExtendedAttributes().add(attr);
ExtendedAttribute taskAttr = attr.createExtendedAttribute();
taskAttr.setFlagValue(true);
task2.getExtendedAttributes().add(taskAttr);
project.save(dataDir + "updated.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteMetadata.class);
long OneSec = 10000000;
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
long OneDayEightHour = 8 * OneHour;
long OneDayTwentyFourHour = 24 * OneHour;
Project project = new Project(dataDir + "New project 2010.mpp");
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2012, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2013, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date toDate = calendar.getTime();
WorkingTime wt = new WorkingTime();
wt.setFromTime(startDate);
wt.setToTime(toDate);
WeekDay day = project.get(Prj.CALENDAR).getWeekDays().toList().get(1);
day.getWorkingTimes().add(wt);
project.get(Prj.CALENDAR).setName("CHANGED NAME!");
Task task = project.getRootTask().getChildren().add("Task 1");
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task.set(Tsk.DURATION, project.getDuration(3));
task.set(Tsk.CONTACT, "Rsc 1");
// new fields
task.set(Tsk.IS_MARKED, true);
task.set(Tsk.IGNORE_WARNINGS, true);
Task task2 = project.getRootTask().getChildren().add("Task 2");
task2.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task2.set(Tsk.CONTACT, "Rsc 2");
project.getTaskLinks().add(task, task2, TaskLinkType.FinishToStart, project.getDuration(-1, TimeUnitType.Day));
calendar.set(2013, java.util.Calendar.DECEMBER, 13, 9, 0, 0);
startDate = calendar.getTime();
project.set(Prj.START_DATE, startDate);
Resource rsc = project.getResources().add("Rsc 1");
rsc.set(Rsc.TYPE, ResourceType.Work);
rsc.set(Rsc.INITIALS, "WR");
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.Prorated);
rsc.set(Rsc.MAX_UNITS, 1d);
rsc.set(Rsc.CODE, "Code 1");
rsc.set(Rsc.GROUP, "Workers");
rsc.set(Rsc.E_MAIL_ADDRESS, "1@gmail.com");
rsc.set(Rsc.WINDOWS_USER_ACCOUNT, "user_acc1");
rsc.set(Rsc.IS_GENERIC, new NullableBool(true));
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.End);
rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(10));
rsc.set(Rsc.STANDARD_RATE_FORMAT, RateFormatType.Day);
rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(15));
rsc.set(Rsc.OVERTIME_RATE_FORMAT, RateFormatType.Hour);
rsc.set(Rsc.IS_TEAM_ASSIGNMENT_POOL, true);
rsc.set(Rsc.COST_CENTER, "Cost Center 1");
ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
assn.set(Asn.UID, 1);
assn.set(Asn.WORK, task.get(Tsk.DURATION));
assn.set(Asn.REMAINING_WORK, assn.get(Asn.WORK));
assn.set(Asn.REGULAR_WORK, assn.get(Asn.WORK));
task.set(Tsk.WORK, assn.get(Asn.WORK));
rsc.set(Rsc.WORK, task.get(Tsk.WORK));
assn.set(Asn.START, task.get(Tsk.START));
assn.set(Asn.FINISH, task.get(Tsk.FINISH));
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
attr.setFieldId(String.valueOf((int) ExtendedAttributeTask.Flag1));
attr.setAlias("Labeled");
project.getExtendedAttributes().add(attr);
ExtendedAttribute taskAttr = new ExtendedAttribute();
taskAttr.setValue("1");
taskAttr.setFieldId(attr.getFieldId());
task2.getExtendedAttributes().add(taskAttr);
project.save(dataDir + "updated.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteUpdatedOutlineCode.class);
String newFile = "New Project 2013.mpp";
String resultFile = "OutputMPP.mpp";
Project project = new Project(dataDir + newFile);
ArrayList projectOutlCodes = new ArrayList();
OutlineCodeDefinition code1 = new OutlineCodeDefinition();
code1.setAlias("New task outline code1");
code1.setFieldId(String.valueOf((int) ExtendedAttributeTask.OutlineCode1));
code1.setFieldName("Outline Code1");
OutlineMask mask = new OutlineMask();
mask.setSeparator("+");
mask.setLevel(1);
mask.setType(MaskType.Numbers);
code1.getMasks().add(mask);
OutlineValue value = new OutlineValue();
value.setDescription("Value description");
value.setValueId(1);
value.setValue("123456");
value.setType(OutlineValueType.Number);
code1.getValues().add(value);
project.getOutlineCodes().add(code1);
OutlineCodeDefinition code2 = new OutlineCodeDefinition();
code2.setAlias("New rsc outline code2");
code2.setFieldId(String.valueOf((int) ExtendedAttributeResource.OutlineCode2));
code2.setFieldName("Outline Code2");
OutlineMask mask2 = new OutlineMask();
mask2.setSeparator("/");
mask2.setLevel(1);
mask2.setType(MaskType.Numbers);
code2.getMasks().add(mask2);
OutlineValue value2 = new OutlineValue();
value2.setDescription("Value2 description");
value2.setValueId(2);
value2.setValue("987654");
value2.setType(OutlineValueType.Number);
project.save(dataDir + "Project.Mpp", SaveFileFormat.MPP);
// Create a project reader instance
Project project = new Project(dataDir + "Project.mpp");
// Custom properties are available through the typed collection:
for (CustomProjectProperty property : project.getCustomProps()) {
System.out.println(property.getType());
System.out.println(property.getName());
System.out.println(property.getValue());
}
// Built-in properties are available directly:
System.out.println(project.getBuiltInProps().getAuthor());
System.out.println(project.getBuiltInProps().getTitle());
// or as an item of built-in property collection:
for (BuiltInProjectProperty property : project.getBuiltInProps()) {
System.out.println(property.getName());
System.out.println(property.getValue());
}
Project project = new Project(dataDir+ "input.xml");
if(project.get(Prj.SCHEDULE_FROM_START).getValue())
System.out.println("Project Start Date : " + project.get(Prj.START_DATE));
else
System.out.println("Project Finish Date : " + project.get(Prj.FINISH_DATE));
String strSchdl = (project.get(Prj.SCHEDULE_FROM_START).getValue())?"Project Start Date":"Project Finish Date";
System.out.println("Project Schedule From : " + strSchdl);
System.out.println("Current Date : " + project.get(Prj.CURRENT_DATE));
System.out.println("Status Date : " + project.get(Prj.STATUS_DATE));
System.out.println("Calendar : " + project.get(Prj.CALENDAR).getName());
//Create a project instance
Project project = new Project();
//Set project information properties
project.set(Prj.SCHEDULE_FROM_START, new NullableBool(true));
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2014, 7, 10);
project.set(Prj.START_DATE,cal.getTime());
project.set(Prj.CURRENT_DATE, cal.getTime());
project.set(Prj.STATUS_DATE, cal.getTime());
//Save the Project as XML
project.save(dataDir + "project3.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConfigureGanttChartView.class);
Project project = new Project(dataDir + "New project 2010.mpp");
// Create a new project task
Task task = project.getRootTask().getChildren().add("New Activity");
// Add custom text attribute to created task.
ExtendedAttribute attr = new ExtendedAttribute();
attr.setFieldId(String.valueOf((int) ExtendedAttributeTask.Text1));
attr.setValue("Activity attribute");
task.getExtendedAttributes().add(attr);
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.setField(Field.TaskText1);
attrField.setWidth(20);
attrField.setTitle("Custom attribute");
attrField.setAlignTitle(StringAlignment.Center);
attrField.setAlignData(StringAlignment.Center);
Table table = project.getTables().toList().get(0);
table.getTableFields().add(3, attrField);
// The result of opening of saved project in MSP2010 is in attached
// screenshot
project.save("saved.mpp", SaveFileFormat.MPP);
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConfigureGanttChartView.class);
Project project = new Project(dataDir + "New project 2010.mpp");
// Create a new project task
Task task = project.getRootTask().getChildren().add("New Activity");
// Define new custom attribute
ExtendedAttributeDefinition text1Definition = ExtendedAttributeDefinition.createTaskDefinition(ExtendedAttributeTask.Text1, null);
project.getExtendedAttributes().add(text1Definition);
// Add custom text attribute to created task.
task.getExtendedAttributes().add(text1Definition.createExtendedAttribute("Activity attribute"));
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.setField(Field.TaskText1);
attrField.setWidth(20);
attrField.setTitle("Custom attribute");
attrField.setAlignTitle(StringAlignment.Center);
attrField.setAlignData(StringAlignment.Center);
Table table = project.getTables().toList().get(0);
table.getTableFields().add(3, attrField);
// The result of opening of saved project in MSP2010 is in attached screenshot
project.save("saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateEmptyProjectFile.class);
//Create a project instance
Project newProject = new Project();
newProject.save(dataDir + "Project1.xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Project file generated Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateEmptyProjectSaveMPP.class);
//Create a project instance
Project newProject = new Project();
newProject.save(dataDir + "Project1.mpp", SaveFileFormat.MPP);
//Display result of conversion.
System.out.println("Project file generated Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateEmptyProjectFile.class);
//Create a project instance
Project newProject = new Project();
// Create a file stream
OutputStream projectStream = new FileOutputStream(dataDir + "EmptyProjectSaveStream_out.xml");
newProject.save(projectStream, SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Project file generated Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CriticalPath.class);
Project project = new Project(dataDir + "New project 2010.mpp");
project.setCalculationMode(CalculationMode.Automatic);
Task subtask1 = project.getRootTask().getChildren().add("1");
Task subtask2 = project.getRootTask().getChildren().add("2");
Task subtask3 = project.getRootTask().getChildren().add("3");
project.getTaskLinks().add(subtask1, subtask2, TaskLinkType.FinishToStart);
// Display the critical path now
for (Task task : project.getCriticalPath()) {
System.out.println(task.get(Tsk.NAME));
}