From 305be7d3ac99ad069467c93e6c64ee779ee76e7c Mon Sep 17 00:00:00 2001 From: llorentelemmc Date: Fri, 8 Nov 2024 16:28:31 +0100 Subject: [PATCH] refactor: resolve conflicts --- .../io/src/app/resource/resource-type.ts | 2 + .../io/src/app/resource/resource.service.ts | 12 --- .../app/resources/resource-types.service.ts | 8 +- .../io/src/app/resources/resourceType.ts | 4 - .../resources/resources-page.component.html | 8 +- .../app/resources/resources-page.component.ts | 2 +- .../permission/permission.component.spec.ts | 24 +++-- .../permission/permission.component.ts | 6 +- .../restriction-add.component.spec.ts | 63 +++++++++++-- .../restriction-edit.component.spec.ts | 91 ++++++++++++++++--- .../boundary/ResourceTypeLocator.java | 17 ++-- .../control/ResourceTypeDomainService.java | 5 - .../entity/ResourceTypeEntity.java | 2 +- .../mobiliar/rest/dtos/ResourceTypeDTO.java | 8 ++ .../rest/resources/ResourceTypesRest.java | 8 -- 15 files changed, 185 insertions(+), 75 deletions(-) delete mode 100644 AMW_angular/io/src/app/resources/resourceType.ts diff --git a/AMW_angular/io/src/app/resource/resource-type.ts b/AMW_angular/io/src/app/resource/resource-type.ts index ef36a96c6..daeaa8d0f 100644 --- a/AMW_angular/io/src/app/resource/resource-type.ts +++ b/AMW_angular/io/src/app/resource/resource-type.ts @@ -1,4 +1,6 @@ export interface ResourceType { id: number; name: string; + hasChildren: boolean; + children: ResourceType[]; } diff --git a/AMW_angular/io/src/app/resource/resource.service.ts b/AMW_angular/io/src/app/resource/resource.service.ts index c57a41067..22befbb2a 100644 --- a/AMW_angular/io/src/app/resource/resource.service.ts +++ b/AMW_angular/io/src/app/resource/resource.service.ts @@ -3,7 +3,6 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; import { Resource } from './resource'; -import { ResourceType } from './resource-type'; import { Release } from './release'; import { Relation } from './relation'; import { Property } from './property'; @@ -66,17 +65,6 @@ export class ResourceService extends BaseService { ); } - getAllResourceTypes(): Observable { - return this.http - .get(`${this.getBaseUrl()}/resources/resourceTypes`, { - headers: this.getHeaders(), - }) - .pipe( - map((resources) => resources.map(toResource)), - catchError(this.handleError), - ); - } - getByType(type: string): Observable { return this.http .get(`${this.getBaseUrl()}/resources?type=${type}`, { diff --git a/AMW_angular/io/src/app/resources/resource-types.service.ts b/AMW_angular/io/src/app/resources/resource-types.service.ts index 0ccc46cf4..bbafd9102 100644 --- a/AMW_angular/io/src/app/resources/resource-types.service.ts +++ b/AMW_angular/io/src/app/resources/resource-types.service.ts @@ -1,10 +1,10 @@ -import { Injectable, Signal } from '@angular/core'; +import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, startWith, Subject } from 'rxjs'; import { toSignal } from '@angular/core/rxjs-interop'; import { shareReplay, switchMap } from 'rxjs/operators'; -import { ResourceType } from './resourceType'; import { BaseService } from '../base/base.service'; +import { ResourceType } from '../resource/resource-type'; @Injectable({ providedIn: 'root' }) export class ResourceTypesService extends BaseService { @@ -25,6 +25,10 @@ export class ResourceTypesService extends BaseService { super(); } + getAllResourceTypes(): Observable { + return this.http.get(`${this.getBaseUrl()}/resources/resourceTypes`); + } + getPredefinedResourceTypes(): Observable { return this.http.get(`${this.getBaseUrl()}/resources/predefinedResourceTypes`); } diff --git a/AMW_angular/io/src/app/resources/resourceType.ts b/AMW_angular/io/src/app/resources/resourceType.ts deleted file mode 100644 index ef36a96c6..000000000 --- a/AMW_angular/io/src/app/resources/resourceType.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface ResourceType { - id: number; - name: string; -} diff --git a/AMW_angular/io/src/app/resources/resources-page.component.html b/AMW_angular/io/src/app/resources/resources-page.component.html index b4e1dbe41..6efa49a4f 100644 --- a/AMW_angular/io/src/app/resources/resources-page.component.html +++ b/AMW_angular/io/src/app/resources/resources-page.component.html @@ -8,8 +8,12 @@ >} diff --git a/AMW_angular/io/src/app/resources/resources-page.component.ts b/AMW_angular/io/src/app/resources/resources-page.component.ts index 57970713e..e335b26a7 100644 --- a/AMW_angular/io/src/app/resources/resources-page.component.ts +++ b/AMW_angular/io/src/app/resources/resources-page.component.ts @@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component, computed, inject, Signal, signal } import { AuthService } from '../auth/auth.service'; import { PageComponent } from '../layout/page/page.component'; import { LoadingIndicatorComponent } from '../shared/elements/loading-indicator.component'; -import { ResourceType } from './resourceType'; import { ResourceTypesService } from './resource-types.service'; +import { ResourceType } from '../resource/resource-type'; @Component({ selector: 'app-resources-page', diff --git a/AMW_angular/io/src/app/settings/permission/permission.component.spec.ts b/AMW_angular/io/src/app/settings/permission/permission.component.spec.ts index cc5286395..e036bd33a 100644 --- a/AMW_angular/io/src/app/settings/permission/permission.component.spec.ts +++ b/AMW_angular/io/src/app/settings/permission/permission.component.spec.ts @@ -16,6 +16,7 @@ import { Restriction } from './restriction'; import { Tag } from './tag'; import { EnvironmentService } from '../../deployment/environment.service'; import { ResourceService } from '../../resource/resource.service'; +import { ResourceTypesService } from '../../resources/resource-types.service'; import { Environment } from 'src/app/deployment/environment'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; @@ -27,6 +28,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { let permissionService: PermissionService; let environmentService: EnvironmentService; let resourceService: ResourceService; + let resourceTypesService: ResourceTypesService; const mockRoute: any = { snapshot: {} }; mockRoute.params = new Subject(); @@ -50,6 +52,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { EnvironmentService, PermissionService, ResourceService, + ResourceTypesService, { provide: ActivatedRoute, useValue: mockRoute }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -63,6 +66,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { permissionService = TestBed.inject(PermissionService); environmentService = TestBed.inject(EnvironmentService); resourceService = TestBed.inject(ResourceService); + resourceTypesService = TestBed.inject(ResourceTypesService); }); it('should have default data', () => { @@ -80,7 +84,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { } as Environment, ]); expect(component.resourceGroups).toEqual([]); - expect(component.resourceTypes).toEqual([{ id: null, name: null }]); + expect(component.resourceTypes).toEqual([{ id: null, name: null, hasChildren: false, children: [] }]); expect(component.restrictionType).toEqual('role'); }); @@ -98,7 +102,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { spyOn(permissionService, 'getAllPermissionEnumValues').and.returnValue(of(permissions)); spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments)); spyOn(resourceService, 'getAllResourceGroups').and.callThrough(); - spyOn(resourceService, 'getAllResourceTypes').and.callThrough(); + spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough(); // when component.ngOnInit(); mockRoute.params.next({ restrictionType: 'role' }); @@ -109,7 +113,7 @@ describe('PermissionComponent without any params (default: type Role)', () => { expect(permissionService.getAllPermissionEnumValues).toHaveBeenCalled(); expect(environmentService.getAllIncludingGroups).toHaveBeenCalled(); expect(resourceService.getAllResourceGroups).toHaveBeenCalled(); - expect(resourceService.getAllResourceTypes).toHaveBeenCalled(); + expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled(); expect(component.permissions).toEqual(permissions); expect(component.restriction).toBeNull(); expect(component.groupedEnvironments['All']).toContain({ @@ -402,6 +406,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => { let permissionService: PermissionService; let environmentService: EnvironmentService; let resourceService: ResourceService; + let resourceTypesService: ResourceTypesService; const mockRoute: any = { snapshot: {} }; mockRoute.params = new Subject(); @@ -424,6 +429,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => { EnvironmentService, PermissionService, ResourceService, + ResourceTypesService, { provide: ActivatedRoute, useValue: mockRoute }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -436,6 +442,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => { permissionService = TestBed.inject(PermissionService); environmentService = TestBed.inject(EnvironmentService); resourceService = TestBed.inject(ResourceService); + resourceTypesService = TestBed.inject(ResourceTypesService); }); it('should invoke some services on ngOnInt', () => { @@ -452,7 +459,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => { spyOn(permissionService, 'getAllPermissionEnumValues').and.returnValue(of(permissions)); spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments)); spyOn(resourceService, 'getAllResourceGroups').and.callThrough(); - spyOn(resourceService, 'getAllResourceTypes').and.callThrough(); + spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough(); spyOn(permissionService, 'getAllUserRestrictionNames').and.callThrough(); // when component.ngOnInit(); @@ -463,7 +470,7 @@ describe('PermissionComponent with param restrictionType (type User)', () => { expect(permissionService.getAllPermissionEnumValues).toHaveBeenCalled(); expect(environmentService.getAllIncludingGroups).toHaveBeenCalled(); expect(resourceService.getAllResourceGroups).toHaveBeenCalled(); - expect(resourceService.getAllResourceTypes).toHaveBeenCalled(); + expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled(); expect(permissionService.getAllUserRestrictionNames).toHaveBeenCalled(); expect(component.permissions).toEqual(permissions); expect(component.restriction).toBeNull(); @@ -502,6 +509,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => { let permissionService: PermissionService; let environmentService: EnvironmentService; let resourceService: ResourceService; + let resourceTypesService: ResourceTypesService; const mockRoute: any = { snapshot: {} }; mockRoute.params = new Subject(); @@ -524,6 +532,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => { EnvironmentService, PermissionService, ResourceService, + ResourceTypesService, { provide: ActivatedRoute, useValue: mockRoute }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -536,6 +545,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => { permissionService = TestBed.inject(PermissionService); environmentService = TestBed.inject(EnvironmentService); resourceService = TestBed.inject(ResourceService); + resourceTypesService = TestBed.inject(ResourceTypesService); }); it('should invoke some services on ngOnInt', () => { // given @@ -565,7 +575,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => { spyOn(permissionService, 'getOwnUserAndRoleRestrictions').and.returnValue(of(restrictions)); spyOn(environmentService, 'getAllIncludingGroups').and.returnValue(of(environments)); spyOn(resourceService, 'getAllResourceGroups').and.callThrough(); - spyOn(resourceService, 'getAllResourceTypes').and.callThrough(); + spyOn(resourceTypesService, 'getAllResourceTypes').and.callThrough(); // when component.ngOnInit(); mockRoute.params.next({ actingUser: 'testUser' }); @@ -578,7 +588,7 @@ describe('PermissionComponent with param actingUser (delegation mode)', () => { expect(component.userNames).not.toContain('testUser'); expect(environmentService.getAllIncludingGroups).toHaveBeenCalled(); expect(resourceService.getAllResourceGroups).toHaveBeenCalled(); - expect(resourceService.getAllResourceTypes).toHaveBeenCalled(); + expect(resourceTypesService.getAllResourceTypes).toHaveBeenCalled(); expect(permissionService.getOwnUserAndRoleRestrictions).toHaveBeenCalled(); expect(component.assignableRestrictions).toEqual(restrictions); expect(component.assignablePermissions).toEqual(permissions); diff --git a/AMW_angular/io/src/app/settings/permission/permission.component.ts b/AMW_angular/io/src/app/settings/permission/permission.component.ts index 32caf2324..c598af52f 100644 --- a/AMW_angular/io/src/app/settings/permission/permission.component.ts +++ b/AMW_angular/io/src/app/settings/permission/permission.component.ts @@ -28,6 +28,7 @@ import { } from '@ng-bootstrap/ng-bootstrap'; import { LoadingIndicatorComponent } from '../../shared/elements/loading-indicator.component'; import { ButtonComponent } from '../../shared/button/button.component'; +import { ResourceTypesService } from '../../resources/resource-types.service'; @Component({ selector: 'app-permission', @@ -62,7 +63,7 @@ export class PermissionComponent implements OnInit { Global: [], }; resourceGroups: Resource[] = []; - resourceTypes: ResourceType[] = [{ id: null, name: null }]; + resourceTypes: ResourceType[] = [{ id: null, name: null, hasChildren: false, children: [] }]; defaultNavItem: string = 'Roles'; // role | user @@ -90,6 +91,7 @@ export class PermissionComponent implements OnInit { private permissionService: PermissionService, private environmentService: EnvironmentService, private resourceService: ResourceService, + private resourceTypesService: ResourceTypesService, private activatedRoute: ActivatedRoute, private location: Location, ) { @@ -392,7 +394,7 @@ export class PermissionComponent implements OnInit { private getAllResourceTypes() { this.isLoading = true; - this.resourceService.getAllResourceTypes().subscribe({ + this.resourceTypesService.getAllResourceTypes().subscribe({ next: (r) => (this.resourceTypes = this.resourceTypes.concat(r)), error: (e) => (this.errorMessage = e), complete: () => (this.isLoading = false), diff --git a/AMW_angular/io/src/app/settings/permission/restriction-add.component.spec.ts b/AMW_angular/io/src/app/settings/permission/restriction-add.component.spec.ts index c895e5550..78ad6fe84 100644 --- a/AMW_angular/io/src/app/settings/permission/restriction-add.component.spec.ts +++ b/AMW_angular/io/src/app/settings/permission/restriction-add.component.spec.ts @@ -218,9 +218,24 @@ describe('RestrictionAddComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.selectedPermissionNames = ['NEO']; restrictionComponent.selectedContextNames = ['T', 'S']; @@ -262,9 +277,24 @@ describe('RestrictionAddComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.selectedPermissionNames = ['NEO']; restrictionComponent.selectedContextNames = ['T']; @@ -306,9 +336,24 @@ describe('RestrictionAddComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.selectedPermissionNames = ['NEO']; restrictionComponent.selectedContextNames = ['T']; diff --git a/AMW_angular/io/src/app/settings/permission/restriction-edit.component.spec.ts b/AMW_angular/io/src/app/settings/permission/restriction-edit.component.spec.ts index a6ab9ce66..cb84f79f2 100644 --- a/AMW_angular/io/src/app/settings/permission/restriction-edit.component.spec.ts +++ b/AMW_angular/io/src/app/settings/permission/restriction-edit.component.spec.ts @@ -110,8 +110,18 @@ describe('RestrictionEditComponent', () => { (restrictionComponent: RestrictionEditComponent) => { // given restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'APPSERVER' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'APPSERVER', + hasChildren: false, + children: [], + }, ]; restrictionComponent.restriction = { resourceTypeName: 'INVALID', @@ -126,8 +136,18 @@ describe('RestrictionEditComponent', () => { (restrictionComponent: RestrictionEditComponent) => { // given restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'APPSERVER' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'APPSERVER', + hasChildren: false, + children: [], + }, ]; restrictionComponent.restriction = { resourceTypeName: 'APPSERVER', @@ -428,9 +448,24 @@ describe('RestrictionEditComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.restriction = { action: 'CREATE', @@ -472,9 +507,24 @@ describe('RestrictionEditComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.restriction = { action: 'CREATE', @@ -515,9 +565,24 @@ describe('RestrictionEditComponent', () => { // given restrictionComponent.delegationMode = true; restrictionComponent.resourceTypes = [ - { id: 1, name: 'APP' }, - { id: 2, name: 'AS' }, - { id: 3, name: 'FOO' }, + { + id: 1, + name: 'APP', + hasChildren: false, + children: [], + }, + { + id: 2, + name: 'AS', + hasChildren: false, + children: [], + }, + { + id: 3, + name: 'FOO', + hasChildren: false, + children: [], + }, ]; restrictionComponent.restriction = { action: 'CREATE', diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceTypeLocator.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceTypeLocator.java index 8f9b1c2a1..c3235d751 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceTypeLocator.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceTypeLocator.java @@ -67,14 +67,13 @@ public List getPredefinedResourceTypes() throws NotFoundExce return predefinedResourceTypes; } - public List getRootResourceTypes() throws NotFoundException { - List allResourceTypes = getAllResourceTypes(); - List predefinedResourceTypes = getPredefinedResourceTypes(); - allResourceTypes.removeAll(predefinedResourceTypes); - return allResourceTypes; - } - - public boolean hasChildren(Integer resourceTypeId) { - return resourceTypeDomainService.hasChildren(resourceTypeId); + public List getRootResourceTypes() { + List rootResourceTypes = new ArrayList<>(); + for (ResourceTypeEntity e : resourceTypeDomainService.getResourceTypes()) { + if (e.getParentResourceType() == null && !ResourceType.createByResourceType(e, null).isDefaultResourceType()) { + rootResourceTypes.add(e); + } + } + return rootResourceTypes; } } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceTypeDomainService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceTypeDomainService.java index 3f0119810..881d696b0 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceTypeDomainService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceTypeDomainService.java @@ -295,9 +295,4 @@ else if (count == null) { return nextIdentifier; } } - - public boolean hasChildren(Integer resourceTypeId) { - ResourceTypeEntity resourceType = getResourceType(resourceTypeId); - return resourceType.hasChildren(); - } } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceTypeEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceTypeEntity.java index ee5ba20f3..9a6a3e2b8 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceTypeEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceTypeEntity.java @@ -66,7 +66,7 @@ public class ResourceTypeEntity extends HasContexts ResourceTypeEntity parentResourceType; @Setter - @OneToMany(mappedBy="parentResourceType", cascade=ALL) + @OneToMany(mappedBy = "parentResourceType", cascade = ALL, fetch = FetchType.EAGER) Set childrenResourceTypes; public Set getChildrenResourceTypes() { diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/ResourceTypeDTO.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/ResourceTypeDTO.java index ffd2da078..6fe317df4 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/ResourceTypeDTO.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/ResourceTypeDTO.java @@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; +import java.util.stream.Collectors; @XmlRootElement(name = "resourceType") @XmlAccessorType(XmlAccessType.FIELD) @@ -36,9 +38,15 @@ public class ResourceTypeDTO { private Integer id; private String name; + private boolean hasChildren; + private List children; public ResourceTypeDTO(ResourceTypeEntity resourceType){ this.id = resourceType.getId(); this.name = resourceType.getName(); + this.hasChildren = resourceType.hasChildren(); + this.children = resourceType.getChildrenResourceTypes().stream() + .map(ResourceTypeDTO::new) + .collect(Collectors.toList()); } } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTypesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTypesRest.java index e87ec6efd..e6871cfa5 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTypesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTypesRest.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import ch.mobi.itc.mobiliar.rest.dtos.ResourceTypeDTO; import ch.puzzle.itc.mobiliar.business.property.boundary.PropertyEditor; @@ -83,11 +82,4 @@ public List getRootResourceTypes() throws NotFoundException { } return resourceTypeDTOs; } - - @Path("/resourceTypes/{resourceTypeId}/hasChildren") - @GET - @ApiOperation(value = "Checks if resource type has children") - public boolean hasChildren(@PathParam("resourceTypeId") int resourceTypeId) { - return resourceTypeLocator.hasChildren(resourceTypeId); - } }