Skip to content

Commit

Permalink
Feat/1039 fix resource navigation links (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit authored Dec 5, 2024
1 parent 67cf1c5 commit 5ae8164
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
1 change: 1 addition & 0 deletions AMW_angular/io/src/app/resource/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface Resource {
version: string;
defaultRelease: Release;
releases: Release[];
defaultResourceId?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ <h1>{{ resourceType().name }}</h1>
<th>Release</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@for (resource of resourceGroupList(); track resource.id) {
<tr>
<td>{{ resource.name }}</td>
<td>{{ resource.defaultRelease ? resource.defaultRelease.release : '' }}</td>
<td>
<a href="/AMW_web/pages/editResourceView.xhtml?ctx=1&id={{ resource.id }}">
<app-button [variant]="'primary'" [size]="'sm'">
<app-icon icon="pencil"></app-icon
></app-button>
</a>
</td>
</tr>
}
</tbody>
</table>
</thead>
<tbody>
@for (resource of resourceGroupList(); track resource.id) {
<tr>
<td>{{ resource.name }}</td>
<td>{{ resource.defaultRelease ? resource.defaultRelease.release : '' }}</td>
<td>
<a
href="/AMW_web/pages/editResourceView.xhtml?ctx=1&id={{
resource.defaultResourceId ? resource.defaultResourceId : resource.id
}}"
>
<app-button [variant]="'primary'" [size]="'sm'"> <app-icon icon="pencil"></app-icon></app-button>
</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.xml.bind.annotation.XmlRootElement;

import ch.puzzle.itc.mobiliar.business.releasing.entity.ReleaseEntity;
import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity;
import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -42,23 +43,30 @@ public class ResourceGroupDTO {
private String type;
private List<ReleaseEntity> releases;
private ReleaseDTO defaultRelease;
private Integer defaultResourceId;

public ResourceGroupDTO(ResourceGroupEntity resourceGroup, List<ReleaseEntity> releases){
public ResourceGroupDTO(ResourceGroupEntity resourceGroup, List<ReleaseEntity> releases) {
this.id = resourceGroup.getId();
this.name = resourceGroup.getName();
this.type = resourceGroup.getResourceType() != null ? resourceGroup.getResourceType().getName(): null;
if(releases!=null && !releases.isEmpty()){
this.type = resourceGroup.getResourceType() != null ? resourceGroup.getResourceType().getName() : null;
if (releases != null && !releases.isEmpty()) {
this.releases = releases;
}
}

public ResourceGroupDTO(ResourceGroupEntity resourceGroup, ReleaseEntity defaultRelease, List<ReleaseEntity> releases){
public ResourceGroupDTO(ResourceGroupEntity resourceGroup,
ReleaseEntity defaultRelease,
List<ReleaseEntity> releases,
ResourceEntity defaultResource) {
this.id = resourceGroup.getId();
this.name = resourceGroup.getName();
this.type = resourceGroup.getResourceType() != null ? resourceGroup.getResourceType().getName(): null;
this.type = resourceGroup.getResourceType() != null ? resourceGroup.getResourceType().getName() : null;
this.defaultRelease = new ReleaseDTO(defaultRelease.getId(), defaultRelease.getName());
if(releases!=null && !releases.isEmpty()){
if (releases != null && !releases.isEmpty()) {
this.releases = releases;
}
if (defaultResource != null) {
this.defaultResourceId = defaultResource.getId();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,24 @@ public List<ResourceGroupDTO> getResourceGroupsByResourceTypeId(
resourceGroups = resourceGroupLocator.getResourceGroups();
}



return resourceGroups.stream().map(resourceGroupEntity -> {
List<ReleaseEntity> releases = resourceGroupEntity.getResources().stream().map(ResourceEntity::getRelease).collect(Collectors.toList());
SortedSet<ReleaseEntity> sortedReleases = releases.stream()
.sorted(Comparator.comparing(ReleaseEntity::getInstallationInProductionAt))
.collect(Collectors.toCollection(TreeSet::new));
ReleaseEntity mostRelevantRelease = this.resourceDependencyResolverService.findMostRelevantRelease(sortedReleases, new Date());
return new ResourceGroupDTO(resourceGroupEntity, mostRelevantRelease, releases);

Map<Integer, ResourceEntity> releaseToResourceMap = new HashMap<>();
for (ResourceEntity res : resourceGroupEntity.getResources()) {
releaseToResourceMap.put(res.getRelease().getId(), res);
}

var defaultResource = releaseToResourceMap.get(mostRelevantRelease.getId());

return new ResourceGroupDTO(resourceGroupEntity, mostRelevantRelease, releases, defaultResource);

}).collect(Collectors.toList());
}

Expand Down

0 comments on commit 5ae8164

Please sign in to comment.