issue-47 #60

Merged
sebastian merged 13 commits from issue-47 into master 2023-11-13 18:54:08 +01:00
7 changed files with 70 additions and 57 deletions
Showing only changes of commit 1ca0ee20ad - Show all commits

View File

@ -4,10 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Fix deleting tasks">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Fix parsing datetime">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/scheduleInfos/AdvancedScheduleFieldInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/scheduleInfos/AdvancedScheduleFieldInfo.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskgroupRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskgroupRepository.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/schedules/advanced-scheduler/advanced-scheduler.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/schedules/advanced-scheduler/advanced-scheduler.component.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -567,14 +570,21 @@
<option name="project" value="LOCAL" />
<updated>1699805283751</updated>
</task>
<option name="localTasksCounter" value="44" />
<task id="LOCAL-00044" summary="Fix parsing datetime">
<option name="closed" value="true" />
<created>1699806194258</created>
<option name="number" value="00044" />
<option name="presentableId" value="LOCAL-00044" />
<option name="project" value="LOCAL" />
<updated>1699806194258</updated>
</task>
<option name="localTasksCounter" value="45" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Fix marking finished task as overdue" />
<MESSAGE value="Write simple Testcase for ci/cd" />
<MESSAGE value="Deactivate Overall System test (temporarly)" />
<MESSAGE value="Fix failing test case" />
@ -599,7 +609,8 @@
<MESSAGE value="Fix wrong date" />
<MESSAGE value="Deploy on docker (not productive yet!)" />
<MESSAGE value="Fix deleting tasks" />
<option name="LAST_COMMIT_MESSAGE" value="Fix deleting tasks" />
<MESSAGE value="Fix parsing datetime" />
<option name="LAST_COMMIT_MESSAGE" value="Fix parsing datetime" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>

View File

@ -6,40 +6,39 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
public class AdvancedScheduleFieldInfo extends ScheduleFieldInfo {
@NotNull
@JsonProperty
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private ZonedDateTime scheduleStartTime;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private LocalDateTime scheduleStartTime;
@NotNull
@JsonProperty
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private ZonedDateTime scheduleStopTime;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private LocalDateTime scheduleStopTime;
public AdvancedScheduleFieldInfo(LocalDateTime scheduleStartTime, LocalDateTime scheduleStopTime) {
this.scheduleStartTime = ZonedDateTime.from(scheduleStartTime);
this.scheduleStopTime = ZonedDateTime.from(scheduleStopTime);
this.scheduleStartTime = scheduleStartTime;
this.scheduleStopTime = scheduleStopTime;
}
public AdvancedScheduleFieldInfo() {
}
public ZonedDateTime getScheduleStartTime() {
public LocalDateTime getScheduleStartTime() {
return scheduleStartTime;
}
public void setScheduleStartTime(ZonedDateTime scheduleStartTime) {
public void setScheduleStartTime(LocalDateTime scheduleStartTime) {
this.scheduleStartTime = scheduleStartTime;
}
public ZonedDateTime getScheduleStopTime() {
public LocalDateTime getScheduleStopTime() {
return scheduleStopTime;
}
public void setScheduleStopTime(ZonedDateTime scheduleStopTime) {
public void setScheduleStopTime(LocalDateTime scheduleStopTime) {
this.scheduleStopTime = scheduleStopTime;
}
}

View File

@ -13,8 +13,6 @@ import java.util.List;
@Repository
public interface TaskgroupRepository extends CrudRepository<Taskgroup, Long> {
boolean existsByTaskgroupNameAndUser(String name, User user);
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1")
List<Taskgroup> findAllByUser(String username);

View File

@ -56,7 +56,7 @@ public class TaskScheduleService {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
AdvancedTaskSchedule advancedTaskSchedule = new AdvancedTaskSchedule(task, scheduleFieldInfo.getScheduleStartTime().toLocalDateTime(), scheduleFieldInfo.getScheduleStopTime().toLocalDateTime());
AdvancedTaskSchedule advancedTaskSchedule = new AdvancedTaskSchedule(task, scheduleFieldInfo.getScheduleStartTime(), scheduleFieldInfo.getScheduleStopTime());
scheduleRepository.save(advancedTaskSchedule);
return new ServiceResult<>(advancedTaskSchedule);
@ -89,8 +89,8 @@ public class TaskScheduleService {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
schedule.setScheduleStart(scheduleFieldInfo.getScheduleStartTime().toLocalDateTime());
schedule.setScheduleEnd(scheduleFieldInfo.getScheduleStopTime().toLocalDateTime());
schedule.setScheduleStart(scheduleFieldInfo.getScheduleStartTime());
schedule.setScheduleEnd(scheduleFieldInfo.getScheduleStopTime());
scheduleRepository.save(schedule);
return new ServiceResult<>(schedule);
}

View File

@ -39,32 +39,34 @@ public class TaskgroupService {
throw new NoSuchElementException();
}
if(!taskgroupRepository.existsByTaskgroupNameAndUser(taskData.getName(), user.get())) {
Taskgroup taskgroup;
if(taskData.getParentID() < 0) {
taskgroup = new Taskgroup(taskData.getName(), user.get());
Taskgroup taskgroup;
if(taskData.getParentID() < 0) {
if(existTaskgroupOnTaskgroupLevel(null, taskData.getName(), username)) {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} else {
Optional<Taskgroup> parentTaskgroup = taskgroupRepository.findById(taskData.getParentID());
if(parentTaskgroup.isEmpty()) {
return new ServiceResult<>(ServiceExitCode.MISSING_ENTITY);
} else {
taskgroup = new Taskgroup(taskData.getName(), user.get());
taskgroup.setParent(parentTaskgroup.get());
parentTaskgroup.get().getChildren().add(taskgroup);
}
taskgroup = new Taskgroup(taskData.getName(), user.get());
}
taskgroupRepository.save(taskgroup);
return new ServiceResult<>(taskgroup);
} else {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} else{
Optional<Taskgroup> parentTaskgroup = taskgroupRepository.findById(taskData.getParentID());
if(parentTaskgroup.isEmpty()) {
return new ServiceResult<>(ServiceExitCode.MISSING_ENTITY);
} else if(existTaskgroupOnTaskgroupLevel(parentTaskgroup.get(), taskData.getName(), username)) {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} else {
taskgroup = new Taskgroup(taskData.getName(), user.get());
taskgroup.setParent(parentTaskgroup.get());
parentTaskgroup.get().getChildren().add(taskgroup);
}
}
taskgroupRepository.save(taskgroup);
return new ServiceResult<>(taskgroup);
}
public ServiceExitCode editTaskgroup(Taskgroup taskgroup, TaskgroupFieldInfo taskgroupFieldInfo) {
if(!taskgroup.getTaskgroupName().equals(taskgroupFieldInfo.getName())) {
//Check if another taskgroup with the new name is already existent for the user of the taskgroup
if(!taskgroupRepository.existsByTaskgroupNameAndUser(taskgroupFieldInfo.getName(), taskgroup.getUser())) {
if(!existTaskgroupOnTaskgroupLevel(taskgroup.getParent(), taskgroupFieldInfo.getName(), taskgroup.getUser().getUsername())) {
taskgroup.setTaskgroupName(taskgroupFieldInfo.getName());
taskgroupRepository.save(taskgroup);
return ServiceExitCode.OK;
@ -76,6 +78,24 @@ public class TaskgroupService {
}
}
private boolean existTaskgroupOnTaskgroupLevel(Taskgroup taskgroup, String taskgroupName, String username) {
if(taskgroup == null) {
List<Taskgroup> topTaskgroups = getTopTaskgroupsByUser(username);
for(Taskgroup taskgroup1 : topTaskgroups) {
if(taskgroup1.getTaskgroupName().equals(taskgroupName)) {
return true;
}
}
} else {
for(Taskgroup sibling : taskgroup.getChildren()) {
if(sibling.getTaskgroupName().equals(taskgroupName)) {
return true;
}
}
}
return false;
}
public void deleteTaskgroup(Taskgroup taskgroup) {
taskgroupRepository.delete(taskgroup);
}

View File

@ -37,25 +37,6 @@ public class TaskgroupRepsitoryTest {
assertEquals(8, result_user1.size());
}
@Test
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
void existsByTaskgroupNameAndUser() {
User testUser1 = testEntityManager.find(User.class, 1L);
User testUser2 = testEntityManager.find(User.class, 2L);
//Situation 1: Taskgroup exists but within another user
assertFalse(taskgroupRepository.existsByTaskgroupNameAndUser("No children", testUser2));
//Situation 2: Taskgroup exists not
assertFalse(taskgroupRepository.existsByTaskgroupNameAndUser("ada", testUser1));
//Situation 3: Taskgroup (top) exists on user
assertTrue(taskgroupRepository.existsByTaskgroupNameAndUser("No children", testUser1));
//Situation 4: Taskgroup exists on user but not on top level
assertTrue(taskgroupRepository.existsByTaskgroupNameAndUser("Taskgroup 1.1", testUser1));
}
@Test
@Sql("classpath:taskgroupRepositoryTestEntries.sql")
void findAllTopTaskgroupsByUser() {

View File

@ -132,6 +132,8 @@ export class AdvancedSchedulerComponent implements OnInit, OnChanges{
schedule() {
if(this.scheduleInfo == undefined) {
console.log("Direct Date" + this.selectedStartTime!.toString())
console.log("Moment Format" + moment(this.selectedStartTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ'))
this.scheduleService.schedulesTaskIDAdvancedPut(this.task!.taskID, {
scheduleStartTime: moment(this.selectedStartTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
scheduleStopTime: moment(this.selectedStopTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ')
@ -141,6 +143,8 @@ export class AdvancedSchedulerComponent implements OnInit, OnChanges{
}
})
} else {
console.log("Direct Date" + this.selectedStartTime!.toString())
console.log("Moment Format" + moment(this.selectedStartTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ'))
this.scheduleService.schedulesScheduleIDAdvancedPost(this.scheduleInfo.scheduleID!, {
scheduleStartTime: moment(this.selectedStartTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
scheduleStopTime: moment(this.selectedStopTime!).format('YYYY-MM-DDTHH:mm:ss.SSSZ')