Add my customize timephasedData ()

Helllo,

I want to make my own time distribution in the details on “Day plannig”, but do not function !!

here is my code: see method “timephasedAssignmentDataGeneration(); and timephasedTaskDataGeneration();”
public class Aspose {
private static Project project;
private static Task task;
private static ResourceAssignment assn;
private static Resource rsc;

private static Date PROJECT_START_DATE;
private static Date PROJECT_FINISH_DATE;

private static Date SUB_TASK1_START_DATE;
private static Date SUB_TASK1_FINISH_DATE;

public static void main(String[] args) throws Exception {
java.util.Calendar calTimeStart = java.util.Calendar.getInstance();
calTimeStart.set(2016,8,5,8,0,0);
PROJECT_START_DATE = calTimeStart.getTime();
SUB_TASK1_START_DATE = calTimeStart.getTime();

java.util.Calendar calTimeFinish = java.util.Calendar.getInstance();
calTimeFinish.set(2016,8,7,17,0,0);
PROJECT_FINISH_DATE = calTimeFinish.getTime();
SUB_TASK1_FINISH_DATE = calTimeFinish.getTime();


License license = new License();
license.setLicense(new java.io.FileInputStream(“Aspose.Tasks.lic”));

project = createProject();
Task task = addTasks(project);
ResourceAssignment ra = addResourcesAndAssignment(task);
printTask();
timephasedAssignmentDataGeneration();
timephasedTaskDataGeneration();
project.recalculate();

createFileMPP(project);
}

private static Project createProject() {
Project project = new Project();
project.set(Prj.START_DATE, PROJECT_START_DATE);
project.set(Prj.FINISH_DATE, PROJECT_FINISH_DATE);
project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));

Calendar cal = project.getCalendars().add(“Default Calendar”);

//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,8,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,17,0,0);
date = calTime.getTime();
wt2.setToTime(date);

myWeekDay.getWorkingTimes().add(wt1);
myWeekDay.getWorkingTimes().add(wt2);
myWeekDay.setDayWorking(true);
cal.getWeekDays().add(myWeekDay);


Calendar.makeStandardCalendar(cal);
project.set(Prj.CALENDAR, cal);

return project;
}

private static Task addTasks(Project project) {
task = project.getRootTask().getChildren().add(“Summary1”);
task.set(Tsk.START, SUB_TASK1_START_DATE);
task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
// task.set(Tsk.ACTUAL_START, SUB_TASK1_START_DATE.toDate());
// task.set(Tsk.ACTUAL_FINISH, SUB_TASK1_FINISH_DATE.toDate());
// task.set(Tsk.DURATION, project.getDuration(3, TimeUnitType.Day));
// task.set(Tsk.START, SUB_TASK1_START_DATE);
// task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
// task.set(Tsk.TYPE, TaskType.FixedUnits);

return task;
}

private static ResourceAssignment addResourcesAndAssignment(Task task) {
rsc = project.getResources().add(“Billel Redouane”);
// task.set(Tsk.PERCENT_COMPLETE, 50);
rsc.set(Rsc.TYPE, ResourceType.Work);

assn = project.getResourceAssignments().add(task.getChildren().getById(1), rsc);
assn.set(Asn.WORK, project.getDuration(24, TimeUnitType.Hour)); // 4 + 4 + 16
//assn.set(Asn.UNITS, 0.5);//Half unit Per day i.e. 4 hours per day

return assn;
}

private static void timephasedAssignmentDataGeneration(){
// List td11 = assn.getTimephasedData(assn.get(Asn.START), assn.get(Asn.FINISH), TimephasedDataType.AssignmentWork).toList();
// //td.get(0).getTimephasedDataType();
//
// System.out.println(td11.size());
// System.out.println(td11.get(0).getValue());
// System.out.println(td11.get(1).getValue());
// System.out.println(td11.get(2).getValue());
// System.out.println(td11.get(3).getValue());
// System.out.println(td11.get(4).getValue());

////////////////////////////////////////
for (TimephasedData tph: assn.getTimephasedData(assn.get(Asn.START), assn.get(Asn.FINISH), TimephasedDataType.AssignmentWork).toList())
{
    assn.getTimephasedData().remove(tph);
}

//Days by Days (Work + Actual…)
java.util.Calendar cal = java.util.Calendar.getInstance();


TimephasedData td = new TimephasedData();
td.setStart(SUB_TASK1_START_DATE);
cal.set(2016, 8, 5, 17, 0, 0); td.setFinish( cal.getTime() );
td.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td.setUnit(1/2);
td.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td);
//tds.add(td);


TimephasedData td1 = new TimephasedData();
cal.set(2016, 8, 6, 8, 0, 0); td1.setStart( cal.getTime() );
cal.set(2016, 8, 6, 17, 0, 0); td1.setFinish( cal.getTime() );
td1.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td1.setUnit(1/2);
td1.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td1);

TimephasedData td2 = new TimephasedData();
cal.set(2016, 8, 7, 8, 0, 0); td2.setStart( cal.getTime() );
cal.set(2016, 8, 7, 17, 0, 0); td2.setFinish( cal.getTime() );
td2.setValue(project.getDuration(16, TimeUnitType.Hour).toString()); //Work or actual
td2.setUnit(16);
td2.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td2);

// TimephasedDataCollection timephasedDataCollection = new TimephasedDataCollection(1, td); //uid
// timephasedDataCollection.add(td);
// assn.setTimephasedData((TimephasedDataCollection) tds);
}

private static void timephasedTaskDataGeneration(){
// List td11 = task.getTimephasedData(task.get(Tsk.START), task.get(Tsk.FINISH), TimephasedDataType.TaskWork).toList();
// //td.get(0).getTimephasedDataType();
//
// System.out.println("timephasedTaskDataGeneration : "+td11.size());
// System.out.println(td11.get(0).getValue());
// System.out.println(td11.get(1).getValue());
// System.out.println(td11.get(2).getValue());
// System.out.println(td11.get(3).getValue());
// System.out.println(td11.get(4).getValue());

////////////////////////////////////////
for (TimephasedData tph: task.getTimephasedData(task.get(Tsk.START), task.get(Tsk.FINISH), TimephasedDataType.TaskWork).toList())
{
    task.getTimephasedData().remove(tph);
}

//Days by Days (Work + Actual…)
java.util.Calendar cal = java.util.Calendar.getInstance();

TimephasedData td = new TimephasedData();
td.setStart(SUB_TASK1_START_DATE);
cal.set(2016, 8, 5, 17, 0, 0); td.setFinish( cal.getTime() );
td.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td.setUnit(1/2);
td.setTimephasedDataType(TimephasedDataType.TaskWork);
task.getTimephasedData().add(td);
//tds.add(td);


TimephasedData td1 = new TimephasedData();
cal.set(2016, 8, 6, 8, 0, 0); td1.setStart( cal.getTime() );
cal.set(2016, 8, 6, 17, 0, 0); td1.setFinish( cal.getTime() );
td1.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td1.setUnit(1/2);
td1.setTimephasedDataType(TimephasedDataType.TaskWork);
task.getTimephasedData().add(td1);

TimephasedData td2 = new TimephasedData();
cal.set(2016, 8, 7, 8, 0, 0); td2.setStart( cal.getTime() );
cal.set(2016, 8, 7, 17, 0, 0); td2.setFinish( cal.getTime() );
td2.setValue(project.getDuration(16, TimeUnitType.Hour).toString()); //Work or actual
td2.setUnit(2);
td2.setTimephasedDataType(TimephasedDataType.TaskWork);
task.getTimephasedData().add(td2);

}

private static void createFileMPP(Project newProject) {
String dataDir = Utils.getDataDir(Aspose.class);
newProject.save(dataDir + “Project1.xml”, SaveFileFormat.XML); //working
// newProject.save(dataDir + “Project1.mpp”, SaveFileFormat.MPP); //Not working
System.out.println(“Project file generated Successfully”);
}

private static void printTask(){
System.out.println("START_DATE : "+task.get(Tsk.START));
System.out.println("FINISH_DATE : "+task.get(Tsk.FINISH));
System.out.println("DURATION : "+task.get(Tsk.DURATION));
System.out.println("Assignment UNITS : "+assn.get(Asn.UNITS));
//System.out.println("ACTUAL_START : "+task.get(Tsk.ACTUAL_START));
//System.out.println("ACTUAL_FINISH : "+task.get(Tsk.ACTUAL_FINISH));
System.out.println("Percent Complete : "+task.get(Tsk.PERCENT_COMPLETE));
}
}

Hi Billel,


Thank you for writing to Aspose support team.

I have reviewed your code and observed few inconsistencies in the createProject() functions as follows:

  • Here calendar object is declared as below.
<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>Calendar cal = project.getCalendars().add(<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;”>“Default Calendar”<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>);

This cal object by default contains 7 entries in the WeekDays collection. After this line of code you added 7 more week days which totals to 14 days in a week, which is wrong. Please set the collection empty before adding the days or modify the existing days and work times so that total remains 7 days a week.

  • You are setting Friday as short day but setting two working times from 8 am to 12 pm and 1 pm to 5 pm. How is it set to short day when timings are similar to other work days?
  • You are trying to set calendar time as follows:
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>calTime.set(1,1,1,8,0,0);
<span style=“font-family: “Times New Roman”; white-space: normal;”>Please not that month value should be given from 0 to 11. When you set this time, it sets year = 1, Month = Feb and day = 1. Please set month as 0 in this case like calTime.set(1,0,1,8,0,0); to avoid any inconsistency.
  • At the end of this function you called following function:
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>Calendar.makeStandardCalendar(cal);
This causes to initialize the cal object again and discards any changes done in the object.

You may please update your code according to the above guidelines and share the feedback again.
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>

OK, My mistake.

Add my new code, please need creat the timephased Data of type "AssignmentWork"
public class Aspose {
private static Project project;
private static Task task;
private static ResourceAssignment assn;
private static Resource rsc;

private static Date PROJECT_START_DATE;// = new DateTime(2016, 9, 5, 8, 0, 0, 0);
private static Date PROJECT_FINISH_DATE;// = new DateTime(2016, 9, 7, 17, 0, 0, 0);

private static Date SUB_TASK1_START_DATE;// = new DateTime(2016, 9, 5, 8, 0, 0, 0);
private static Date SUB_TASK1_FINISH_DATE;// = new DateTime(2016, 9, 7, 17, 0, 0, 0);

public static void main(String[] args) throws Exception {
java.util.Calendar calTimeStart = java.util.Calendar.getInstance();
calTimeStart.set(2016,8,5,8,0,0);
PROJECT_START_DATE = calTimeStart.getTime();
SUB_TASK1_START_DATE = calTimeStart.getTime();

java.util.Calendar calTimeFinish = java.util.Calendar.getInstance();
calTimeFinish.set(2016,8,7,17,0,0);
PROJECT_FINISH_DATE = calTimeFinish.getTime();
SUB_TASK1_FINISH_DATE = calTimeFinish.getTime();


License license = new License();
license.setLicense(new java.io.FileInputStream(“Aspose.Tasks.lic”));

project = createProject();
Task task = addTasks(project);
ResourceAssignment ra = addResourcesAndAssignment(task);
printTask();
timephasedAssignmentDataGeneration();
//timephasedTaskDataGeneration();
// project.recalculate();

createFileMPP(project); //
}

private static Project createProject() {
Project project = new Project();
project.set(Prj.START_DATE, PROJECT_START_DATE);
project.set(Prj.FINISH_DATE, PROJECT_FINISH_DATE);
project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));

//I used Standar Calendar
// Calendar cal = project.getCalendars().add(“Default Calendar”);
// Calendar.makeStandardCalendar(cal);

return project;
}

private static Task addTasks(Project project) {
task = project.getRootTask().getChildren().add(“Summary1”);
task.set(Tsk.START, SUB_TASK1_START_DATE);
task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
// task.set(Tsk.ACTUAL_START, SUB_TASK1_START_DATE.toDate());
// task.set(Tsk.ACTUAL_FINISH, SUB_TASK1_FINISH_DATE.toDate());
// task.set(Tsk.DURATION, project.getDuration(3, TimeUnitType.Day));
// task.set(Tsk.START, SUB_TASK1_START_DATE);
// task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
task.set(Tsk.TYPE, TaskType.FixedUnits);
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);

return task;
}

private static ResourceAssignment addResourcesAndAssignment(Task task) {
rsc = project.getResources().add(“Billel Redouane”);
// rsc.set(Rsc.TYPE, ResourceType.Work);

assn = project.getResourceAssignments().add(task.getChildren().getById(1), rsc); //subtask1
assn.set(Asn.WORK, project.getDuration(24, TimeUnitType.Hour)); //4 + 4 + 16
// assn.set(Asn.UNITS, 0.5);//Half unit Per day i.e. 4 hours per day
assn.set(Asn.WORK_CONTOUR, WorkContourType.Contoured);

return assn;
}

private static void timephasedAssignmentDataGeneration(){
//Days by Days (Work + Actual…)
java.util.Calendar cal = java.util.Calendar.getInstance();

TimephasedData td = new TimephasedData();
td.setUid(assn.get(Asn.UID));
td.setStart(SUB_TASK1_START_DATE);
cal.set(2016, 8, 6, 8, 0, 0); td.setFinish( cal.getTime() );
td.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td.setUnit(TimeUnitType.Hour);
td.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td);


TimephasedData td1 = new TimephasedData();
td1.setUid(assn.get(Asn.UID));
cal.set(2016, 8, 6, 8, 0, 0); td1.setStart( cal.getTime() );
cal.set(2016, 8, 7, 8, 0, 0); td1.setFinish( cal.getTime() );
td1.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td1.setUnit(TimeUnitType.Hour);
td1.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td1);

TimephasedData td2 = new TimephasedData();
td1.setUid(assn.get(Asn.UID));
cal.set(2016, 8, 7, 8, 0, 0); td2.setStart( cal.getTime() );
cal.set(2016, 8, 8, 8, 0, 0); td2.setFinish( cal.getTime() );
td2.setValue(project.getDuration(16, TimeUnitType.Hour).toString()); //Work or actual
td2.setUnit(TimeUnitType.Hour);
td2.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td2);

// TimephasedDataCollection timephasedDataCollection = new TimephasedDataCollection(1, td); //uid
// timephasedDataCollection.add(td);
// assn.setTimephasedData((TimephasedDataCollection) tds);
}

private static void createFileMPP(Project newProject) {
String dataDir = Utils.getDataDir(Aspose.class);
newProject.save(dataDir + “Project1.xml”, SaveFileFormat.XML); //working
// newProject.save(dataDir + “Project1.mpp”, SaveFileFormat.MPP); //Not working
System.out.println(“Project file generated Successfully”);
}

private static void printTask(){
System.out.println("START_DATE : "+task.get(Tsk.START));
System.out.println("FINISH_DATE : "+task.get(Tsk.FINISH));
System.out.println("DURATION : "+task.get(Tsk.DURATION));
System.out.println("Assignment UNITS : "+assn.get(Asn.UNITS));
// System.out.println("ACTUAL_START : "+task.get(Tsk.ACTUAL_START));
// System.out.println("ACTUAL_FINISH : "+task.get(Tsk.ACTUAL_FINISH));
System.out.println("Percent Complete : "+task.get(Tsk.PERCENT_COMPLETE));
}
}
At the end I have my XML file:
      
1
2
2016-09-05T08:00:00
2016-09-06T08:00:00
2
PT8H0M0S


1
2
2016-09-06T08:00:00
2016-09-07T08:00:00
2
PT8H0M0S


1
2
2016-09-07T08:00:00
2016-09-08T08:00:00
2
PT8H0M0S




I don’t want 3 first that Aspose.tasks generated

Hi Billel,


Thank you for sharing feedback.

We have executed your shared code and didn’t find any anomaly. The generated task with assignment has the expected timephased data as you can see in the attached XML file. Could you please check it at your end and also verify if you are using the latest version of the API.

Hello,

I managed to do what I want, but when I use “TimephasedDataType.<span style=“color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9pt; background-color: rgb(52, 65, 52);”>AssignmentWork” that does not function and gives me “</ TimephasedData>” empty which should not be the case.

More when I generate “<span style=“color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9pt; background-color: rgb(43, 43, 43);”>TimephasedDataType.<span style=“color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9pt; background-color: rgb(52, 65, 52);”>AssignmentActualWork” I have a duplicate of the Type 2 as:
2
3
2016-09-28T08:00:00
2016-09-28T17:00:00
1
PT8H0M0S
2
3
2016-09-28T08:00:00
2016-09-28T17:00:00
1
PT8H0M0S

How it is possible to fix this?

Thank you!

///
My version Aspose is : 9.5.0

pom.xml :

com.aspose
aspose-tasks
9.5.0


AsposeJavaAPI
Aspose Java API

http://maven.aspose.com/artifactory/simple/ext-release-local/


Hi Billel,


I have tried to re-produce this issue using your sample code but could not succeed as shown in the XML file shared by me in the previous post. Could you please share some simple application which can be compiled and executed here to re-produce the scenario? It will help us to observe the issue and provide assistance accordingly.

Hello,

When used the “project.calculate ();” nothing seems to be changing, is there a lack or action that I have to do to force the recalculation of the project?


Hi Billel,


Could you please share your complete sample runnable code with us that we can use to reproduce this problem at our end? Till yet, we are unable to reproduce this issue at our end via the sample code you have shared and we can’t be of any help to you unless we can reproduce the issue at our end. We appreciate your understanding in this regard.

Hi Billel,


We are analyzing this issue and request you to spare us little time. We will write back here soon to share the feedback.

Hi Billel,


I have executed your code and observed that while using sample code here, the timephased data entries are repeated for AssignmentActualWork in the XML file. Could you please re-confirm that this the only issue in the above mentioned sample code? Once confirmed, I will log this issue. Also please try to create separate threads for different issues (if possible) as it helps to keep track of each issue properly.

Two issue:

1- The timephased data entries are repeated for AssignmentActualWork in the XML file.

2- The “project.recalculate ();” in my sample code that appears not well. (My FINISH_DATE is not same that is displayed by MS Project, MS Project displays the correct date)

3 - in Sample code “TimephasedDataType.AssignmentWork” non functional, I went use the “AssignmentRemainingWork” what is not normal and it causes complications. (result " " only)

Hi Billel,

Thank you for providing more details. Following is the feedback.

1. This issue is re-produced and logged under Id:TASKSJAVA-246 for further investigation by the product team.

2. I have observed the difference but need further clarifications. You mentioned that Microsoft Project displays correct date. Here the image is attached showing dates in XML and MPP both. Could you please comment if these dates are correct? To me these are different than the dates added in the sample code. I will provide further assistance once the feedback is available.

3. This issue is re-produced and logged under Id:TASKSJAVA-247 for further investigation by the product team.

For point 2 :

- After the update timePhaseData the project should be re-calculate (call : "project.recalculate ();).

- This because my XML takes not recalculate values as the FINISH_DATE (see also the console output printTask () method).

- MsProject load the XML. For the .MPP file the tiket was opened TASKSJAVA-245 therefore not rely on this .MPP.

Hi Billel,


Thank you for providing more description. This issue is also re-produced and logged under Id: TASKSJAVA-248 for further investigation by the product team.You will be automatically notified once any update is received in this regard.
Hello,
For the Ticket Id:TASKSJAVA-247 (point 3 tell the "AssignmentWork").
I must have a TimePahseData with Type : 81 (ref : https://reference.aspose.com/tasks/net/aspose.tasks/timephaseddatatype/)

Instead I have this could it be explained by a lack of data on input (Task or Resource or ResourceAssignment). Yes if the what. (See for reproduce the case below))

billel.redouane:
OK, My mistake.
Add my new code, please need creat the timephased Data of type "AssignmentWork"
public class Aspose {
private static Project project;
private static Task task;
private static ResourceAssignment assn;
private static Resource rsc;

private static Date PROJECT_START_DATE;// = new DateTime(2016, 9, 5, 8, 0, 0, 0);
private static Date PROJECT_FINISH_DATE;// = new DateTime(2016, 9, 7, 17, 0, 0, 0);

private static Date SUB_TASK1_START_DATE;// = new DateTime(2016, 9, 5, 8, 0, 0, 0);
private static Date SUB_TASK1_FINISH_DATE;// = new DateTime(2016, 9, 7, 17, 0, 0, 0);

public static void main(String[] args) throws Exception {
java.util.Calendar calTimeStart = java.util.Calendar.getInstance();
calTimeStart.set(2016,8,5,8,0,0);
PROJECT_START_DATE = calTimeStart.getTime();
SUB_TASK1_START_DATE = calTimeStart.getTime();

java.util.Calendar calTimeFinish = java.util.Calendar.getInstance();
calTimeFinish.set(2016,8,7,17,0,0);
PROJECT_FINISH_DATE = calTimeFinish.getTime();
SUB_TASK1_FINISH_DATE = calTimeFinish.getTime();


License license = new License();
license.setLicense(new java.io.FileInputStream("Aspose.Tasks.lic"));

project = createProject();
Task task = addTasks(project);
ResourceAssignment ra = addResourcesAndAssignment(task);
printTask();
timephasedAssignmentDataGeneration();
//timephasedTaskDataGeneration();
// project.recalculate();

createFileMPP(project); //
}

private static Project createProject() {
Project project = new Project();
project.set(Prj.START_DATE, PROJECT_START_DATE);
project.set(Prj.FINISH_DATE, PROJECT_FINISH_DATE);
project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));

//I used Standar Calendar
// Calendar cal = project.getCalendars().add("Default Calendar");
// Calendar.makeStandardCalendar(cal);

return project;
}

private static Task addTasks(Project project) {
task = project.getRootTask().getChildren().add("Summary1");
task.set(Tsk.START, SUB_TASK1_START_DATE);
task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
// task.set(Tsk.ACTUAL_START, SUB_TASK1_START_DATE.toDate());
// task.set(Tsk.ACTUAL_FINISH, SUB_TASK1_FINISH_DATE.toDate());
// task.set(Tsk.DURATION, project.getDuration(3, TimeUnitType.Day));
// task.set(Tsk.START, SUB_TASK1_START_DATE);
// task.set(Tsk.FINISH, SUB_TASK1_FINISH_DATE);
task.set(Tsk.TYPE, TaskType.FixedUnits);
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);

return task;
}

private static ResourceAssignment addResourcesAndAssignment(Task task) {
rsc = project.getResources().add("Billel Redouane");
// rsc.set(Rsc.TYPE, ResourceType.Work);

assn = project.getResourceAssignments().add(task.getChildren().getById(1), rsc); //subtask1
assn.set(Asn.WORK, project.getDuration(24, TimeUnitType.Hour)); //4 + 4 + 16
// assn.set(Asn.UNITS, 0.5);//Half unit Per day i.e. 4 hours per day
assn.set(Asn.WORK_CONTOUR, WorkContourType.Contoured);

return assn;
}

private static void timephasedAssignmentDataGeneration(){

//Delete All TimephasedDataType genereted by Aspose.
        for (TimephasedData tph: assn.getTimephasedData().toList()) {
assn.getTimephasedData().remove(tph);
}
//Days by Days (Work + Actual....)
java.util.Calendar cal = java.util.Calendar.getInstance();

TimephasedData td = new TimephasedData();
td.setUid(assn.get(Asn.UID));
td.setStart(SUB_TASK1_START_DATE);
cal.set(2016, 8, 6, 8, 0, 0); td.setFinish( cal.getTime() );
td.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td.setUnit(TimeUnitType.Hour);
td.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td);


TimephasedData td1 = new TimephasedData();
td1.setUid(assn.get(Asn.UID));
cal.set(2016, 8, 6, 8, 0, 0); td1.setStart( cal.getTime() );
cal.set(2016, 8, 7, 8, 0, 0); td1.setFinish( cal.getTime() );
td1.setValue(project.getDuration(4, TimeUnitType.Hour).toString()); //Work or actual
td1.setUnit(TimeUnitType.Hour);
td1.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td1);

TimephasedData td2 = new TimephasedData();
td1.setUid(assn.get(Asn.UID));
cal.set(2016, 8, 7, 8, 0, 0); td2.setStart( cal.getTime() );
cal.set(2016, 8, 8, 8, 0, 0); td2.setFinish( cal.getTime() );
td2.setValue(project.getDuration(16, TimeUnitType.Hour).toString()); //Work or actual
td2.setUnit(TimeUnitType.Hour);
td2.setTimephasedDataType(TimephasedDataType.AssignmentWork);
assn.getTimephasedData().add(td2);

// TimephasedDataCollection timephasedDataCollection = new TimephasedDataCollection(1, td); //uid
// timephasedDataCollection.add(td);
// assn.setTimephasedData((TimephasedDataCollection) tds);
}

private static void createFileMPP(Project newProject) {
String dataDir = Utils.getDataDir(Aspose.class);
newProject.save(dataDir + "Project1.xml", SaveFileFormat.XML); //working
// newProject.save(dataDir + "Project1.mpp", SaveFileFormat.MPP); //Not working
System.out.println("Project file generated Successfully");
}

private static void printTask(){
System.out.println("START_DATE : "+task.get(Tsk.START));
System.out.println("FINISH_DATE : "+task.get(Tsk.FINISH));
System.out.println("DURATION : "+task.get(Tsk.DURATION));
System.out.println("Assignment UNITS : "+assn.get(Asn.UNITS));
//System.out.println("ACTUAL_START : "+task.get(Tsk.ACTUAL_START));
//System.out.println("ACTUAL_FINISH : "+task.get(Tsk.ACTUAL_FINISH));
System.out.println("Percent Complete : "+task.get(Tsk.PERCENT_COMPLETE));
}
}
At the end I have my XML file:
   
      
      
      

I don't want that Aspose.tasks generated

Hi Billel,


Thank you for writing to us again.

Same issue is logged under this ticket TASKSJAVA-247 where empty tags are generated by Aspose.Tasks for AssignmentWork. You will be automatically notified once any update is received in this regard.

The issues you have found earlier (filed as TASKSJAVA-247) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

@billel.redouane,

We have investigated the issue reported under Ticket TASKSJAVA-246 and observed few issues. Please notice in the following code sample that a TimePhasedData object is created as follows:

TimephasedData td = new TimephasedData(); 

Few properties of “td” are set and then added in timephased data collection of resource assignment “assn” as follows:

assn.getTimephasedData().add(td);

Immediate after this line of code, properties are further changed and added again as follows:

td.setValue("PT4H0M0S");
td.setTimephasedDataType(TimephasedDataType.AssignmentActualWork);
assn.getTimephasedData().add(td);

This thing is causing issues as once the timephased object is added to collection, it is not copied and if we change the values in td, it changes data for previous items of the collection also.

You may please always create a new timephased data item using the “new” keyword for adding it to collection, as once it is added into collection, it is not supposed to be copied and any change in this object will affect all collection items referring to it. Hope this clarifies the issue. Please update your code with reference to above suggestions and test the scenario again.

Following sample code shows the issue with comments. Similar issues are there in other places as well.

private static void timephasedAssignmentDataGeneration(){
    ////////////////////////////////////////
    for (TimephasedData tph: assn.getTimephasedData().toList()) //assn.get(Asn.START), assn.get(Asn.FINISH), TimephasedDataType.AssignmentWork
    {
        assn.getTimephasedData().remove(tph);
    }

    java.util.Calendar cal = java.util.Calendar.getInstance();

    TimephasedData td = new TimephasedData();
    td.setUid(assn.get(Asn.UID));
    td.setStart(SUB_TASK1_START_DATE);
    cal.set(2016,8,27,8,0,0); td.setFinish( cal.getTime() );
    td.setValue("PT0H0M0S");
    td.setUnit(TimeUnitType.Hour);
    td.setTimephasedDataType(TimephasedDataType.AssignmentRemainingWork);
    assn.getTimephasedData().add(td);

    //ISSUE STARTS HERE WHEN CHANGES ARE MADE IN td AND ADDED AGAIN IN COLLECTION. IT CAUSES CHANGES IN PREVIOUS COLLECTION ITEMS AS WELL
    td.setValue("PT4H0M0S");
    td.setTimephasedDataType(TimephasedDataType.AssignmentActualWork);
    assn.getTimephasedData().add(td);

The issues you have found earlier (filed as TASKSJAVA-248) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal