forked from migtools/tackle-application-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TACKLE-58: tag type and business service controls endpoint integration
- Loading branch information
Showing
9 changed files
with
234 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/io/tackle/applicationinventory/BusinessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.tackle.applicationinventory; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BusinessService { | ||
public String id; | ||
public String name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.tackle.applicationinventory; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class TagType { | ||
public String id; | ||
public String name; | ||
public List<Tag> tags; | ||
|
||
public static class Tag { | ||
public String id; | ||
public String name; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/io/tackle/applicationinventory/mapper/ApplicationInventoryAPIMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,83 @@ | ||
package io.tackle.applicationinventory.mapper; | ||
|
||
import io.tackle.applicationinventory.BusinessService; | ||
import io.tackle.applicationinventory.TagType; | ||
import io.tackle.applicationinventory.entities.Application; | ||
import io.tackle.applicationinventory.entities.ApplicationImport; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.core.Response; | ||
import java.util.*; | ||
|
||
|
||
public class ApplicationInventoryAPIMapper extends ApplicationMapper{ | ||
|
||
public ApplicationInventoryAPIMapper( Set<TagType> tagTypes, Set<BusinessService> businessServices) { | ||
super(tagTypes, businessServices); | ||
} | ||
|
||
@Override | ||
public Response map(ApplicationImport importApp) | ||
{ | ||
System.out.println("Call to Mapper"); | ||
|
||
Application newApp = new Application(); | ||
Set<String> tags = new HashSet<>(); | ||
try { | ||
newApp.businessService = addBusinessService(importApp.getBusinessService()); | ||
newApp.comments = importApp.getComments(); | ||
newApp.description = importApp.getDescription(); | ||
newApp.name = importApp.getApplicationName(); | ||
if (importApp.getTagType1() != null && importApp.getTag1() != null) { | ||
tags.add(addTag(importApp.getTag1(), importApp.getTagType1())); | ||
} | ||
if (importApp.getTagType2() != null && importApp.getTag2() != null) { | ||
tags.add(addTag(importApp.getTag2(), importApp.getTagType2())); | ||
} | ||
if (importApp.getTagType3() != null && importApp.getTag3() != null) { | ||
tags.add(addTag(importApp.getTag3(), importApp.getTagType3())); | ||
} | ||
if (importApp.getTagType4() != null && importApp.getTag4() != null) { | ||
tags.add(addTag(importApp.getTag4(), importApp.getTagType4())); | ||
} | ||
} | ||
catch(NoSuchElementException nsee) | ||
{ | ||
nsee.printStackTrace(); | ||
return Response.serverError().build(); | ||
} | ||
|
||
newApp.tags = tags; | ||
newApp.persistAndFlush(); | ||
return Response.ok().build(); | ||
} | ||
|
||
|
||
private String addBusinessService(String businessServiceName) throws NoSuchElementException | ||
{ | ||
Optional<BusinessService> businessServiceOptional = businessServices.stream().filter(businessServiceControls -> businessServiceControls.name.equals(businessServiceName)) | ||
.findFirst(); | ||
|
||
|
||
return businessServiceOptional.orElseThrow().id; | ||
|
||
} | ||
|
||
|
||
private String addTag(String tagName, String tagTypeName) throws NoSuchElementException | ||
{ | ||
Optional<TagType> tagTypeOptional = tagTypes.stream().filter(tagTypeControls -> tagTypeControls.name.equals(tagTypeName)) | ||
.findFirst(); | ||
if(!tagTypeOptional.isPresent()) | ||
{ | ||
return null; | ||
} | ||
Optional<TagType.Tag> tagOptional = tagTypeOptional.get().tags.stream().filter(tagControls -> tagControls.name.equals(tagName)) | ||
.findFirst(); | ||
|
||
return tagOptional.orElseThrow().id; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/io/tackle/applicationinventory/mapper/ApplicationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package io.tackle.applicationinventory.mapper; | ||
|
||
import io.tackle.applicationinventory.BusinessService; | ||
import io.tackle.applicationinventory.TagType; | ||
import io.tackle.applicationinventory.entities.ApplicationImport; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.core.Response; | ||
import java.util.Set; | ||
|
||
public abstract class ApplicationMapper { | ||
@ApplicationScoped | ||
Set<TagType> tagTypes; | ||
@ApplicationScoped | ||
Set<BusinessService> businessServices; | ||
|
||
public ApplicationMapper(Set<TagType> tagTypes, Set<BusinessService> businessServices) | ||
{ | ||
this.tagTypes = tagTypes; | ||
this.businessServices = businessServices; | ||
} | ||
|
||
public abstract Response map(ApplicationImport importApp); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/io/tackle/applicationinventory/service/BusinessServiceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.tackle.applicationinventory.service; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.tackle.applicationinventory.BusinessService; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import java.util.Set; | ||
|
||
|
||
@Path("/controls/business-service") | ||
@RegisterRestClient | ||
@ApplicationScoped | ||
public interface BusinessServiceService { | ||
|
||
@GET | ||
@Path("?page=0&size=1000&sort=name") | ||
Set<BusinessService> getListOfBusinessServices(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/io/tackle/applicationinventory/service/TagTypeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.tackle.applicationinventory.service; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.tackle.applicationinventory.TagType; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import java.util.Set; | ||
|
||
|
||
@Path("/controls/tag-type") | ||
@RegisterRestClient | ||
@ApplicationScoped | ||
public interface TagTypeService { | ||
|
||
@GET | ||
@Path("?page=0&size=1000&sort=rank") | ||
Set<TagType> getListOfTagTypes(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters