-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TACKLE-312: import dependencies (#136)
* TACKLE-312: import dependencies * TACKLE-312: add validation for dependency import * TACKLE-312: dependency import change literals 'from' and 'to' to southbound and northbound * TACKLE-312: code test coverage * TACKLE-312: import dependencies make dependency direction case insensitive * TACKLE-312: applicationsDependency hibernatevalidator first cut * TACKLE-312: applications depependency cycle validation * TACKLE-312: dependency import cycle check change of approach to validation * TACKLE-312: code test coverage * TACKLE-312: change instantiation of ApplicationDependencyAPIMapper
- Loading branch information
Showing
12 changed files
with
340 additions
and
50 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
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
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
86 changes: 86 additions & 0 deletions
86
src/main/java/io/tackle/applicationinventory/mapper/ApplicationDependencyAPIMapper.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,86 @@ | ||
package io.tackle.applicationinventory.mapper; | ||
|
||
import io.tackle.applicationinventory.entities.Application; | ||
import io.tackle.applicationinventory.entities.ApplicationImport; | ||
import io.tackle.applicationinventory.entities.ApplicationsDependency; | ||
import io.tackle.applicationinventory.exceptions.ApplicationsInventoryException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.core.Response; | ||
|
||
@ApplicationScoped | ||
public class ApplicationDependencyAPIMapper extends ApplicationMapper { | ||
|
||
private static final String FROM_DIRECTION = "SOUTHBOUND"; | ||
private static final String TO_DIRECTION = "NORTHBOUND"; | ||
|
||
public ApplicationDependencyAPIMapper() { | ||
super(null, null); | ||
} | ||
|
||
@Override | ||
public Response map(ApplicationImport importApp, Long parentId) | ||
{ | ||
Application application = null; | ||
Application applicationDependency = null; | ||
if (importApp.getApplicationName() != null) | ||
{ | ||
application = Application.find("name", importApp.getApplicationName()).firstResult(); | ||
} | ||
|
||
if (application == null) | ||
{ | ||
importApp.setErrorMessage("Invalid Application Name"); | ||
return Response.serverError().build(); | ||
} | ||
|
||
if (importApp.getDependency() != null) | ||
{ | ||
applicationDependency = Application.find("name", importApp.getDependency()).firstResult(); | ||
} | ||
|
||
if (applicationDependency == null) | ||
{ | ||
importApp.setErrorMessage("Invalid Dependency"); | ||
return Response.serverError().build(); | ||
} | ||
|
||
ApplicationsDependency dependency = new ApplicationsDependency(); | ||
|
||
if (importApp.getDependencyDirection() != null && importApp.getDependencyDirection().equalsIgnoreCase(FROM_DIRECTION)) | ||
{ | ||
dependency.from = application; | ||
dependency.to = applicationDependency; | ||
} | ||
else if (importApp.getDependencyDirection() != null && importApp.getDependencyDirection().equalsIgnoreCase(TO_DIRECTION)) | ||
{ | ||
dependency.from = applicationDependency; | ||
dependency.to = application; | ||
} | ||
else | ||
{ | ||
importApp.setErrorMessage("Invalid Dependency Direction"); | ||
return Response.serverError().build(); | ||
} | ||
|
||
ApplicationsDependency found = ApplicationsDependency.find("to_id = ?1 and from_id = ?2", dependency.to.id, dependency.from.id).firstResult(); | ||
|
||
if(found != null) | ||
{ | ||
importApp.setErrorMessage("Dependency already exists"); | ||
return Response.serverError().build(); | ||
} | ||
|
||
try{ | ||
ApplicationsDependency.validate(dependency.from, dependency.to); | ||
}catch(ApplicationsInventoryException aie) | ||
{ | ||
importApp.setErrorMessage(aie.getMessage()); | ||
return aie.getResponse(); | ||
} | ||
|
||
dependency.persistAndFlush(); | ||
|
||
return Response.ok().build(); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/main/resources/db/migration/V20210914.1__alter_application_import.sql
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,3 @@ | ||
alter table if exists application_import | ||
add column dependency varchar (255), | ||
add column dependencyDirection varchar (50); |
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
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
Oops, something went wrong.