mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding platform retrieval based on tag and getting platform tags
This commit is contained in:
parent
068edaa157
commit
48fbc40bd2
@ -134,10 +134,12 @@ public interface PlatformManagementAPI {
|
||||
+ "- ENABLED: The platforms that are currently enabled for the tenant\n"
|
||||
+ "- DISABLED: The platforms that can be used by the tenant but disabled "
|
||||
+ "to be used for tenant\n"
|
||||
+ "- ALL: All the list of platforms that can be used by the tenant", required = false)
|
||||
+ "- ALL: All the list of platforms that can be used by the tenant")
|
||||
@QueryParam("status")
|
||||
@Size(max = 45)
|
||||
String status
|
||||
String status,
|
||||
@ApiParam(name = "tag", defaultValue = "Tag value that we need to search the platform for")
|
||||
@QueryParam("tag") String tag
|
||||
);
|
||||
|
||||
@GET
|
||||
@ -340,4 +342,38 @@ public interface PlatformManagementAPI {
|
||||
String status
|
||||
);
|
||||
|
||||
@GET
|
||||
@Path("tags")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get platform tags that starts with the given character sequence",
|
||||
notes = "This will get all platform tags that has the given character sequence ",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:add")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully retrieved platform tags.",
|
||||
response = Platform.class,
|
||||
responseContainer = "List"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform tags.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getPlatformTags(
|
||||
@ApiParam(name = "name", value ="The initial part of the name of platform tags that we need to retrieve",
|
||||
required = true)
|
||||
@QueryParam("name") @Size(min = 3) String name
|
||||
);
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
|
||||
@GET
|
||||
@Override
|
||||
public Response getPlatforms(@QueryParam("status") String status) {
|
||||
public Response getPlatforms(@QueryParam("status") String status, @QueryParam("tag") String tag) {
|
||||
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -61,6 +61,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
try {
|
||||
List<Platform> platforms = APIUtil.getPlatformManager().getPlatforms(tenantID);
|
||||
List<Platform> results;
|
||||
List<Platform> filteredPlatforms = new ArrayList<>();
|
||||
if (status != null) {
|
||||
if (status.contentEquals(ALL_STATUS)) {
|
||||
results = platforms;
|
||||
@ -84,10 +85,22 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
} else {
|
||||
results = platforms;
|
||||
}
|
||||
|
||||
if (tag != null) {
|
||||
if (results != null) {
|
||||
for (Platform platform : results) {
|
||||
if (platform.getTags() != null && platform.getTags().contains(tag)) {
|
||||
filteredPlatforms.add(platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filteredPlatforms = results;
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms with the status " + status + " : " + results.size());
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(results).build();
|
||||
return Response.status(Response.Status.OK).entity(filteredPlatforms).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while getting the platforms for tenant - " + tenantID, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
@ -190,4 +203,22 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("tags")
|
||||
@Override
|
||||
public Response getPlatformTags(@QueryParam("name") String name) {
|
||||
if (name == null || name.isEmpty() || name.length() < 3) {
|
||||
return APIUtil.getResponse("In order to get platform tags, it is required to pass the first 3 "
|
||||
+ "characters of the platform tag name", Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
try {
|
||||
List<String> platformTags = APIUtil.getPlatformManager().getPlatformTags(name);
|
||||
return Response.status(Response.Status.OK).entity(platformTags).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Platform Management Exception while trying to get the platform tags with starting character "
|
||||
+ "sequence " + name, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,4 +133,12 @@ public interface PlatformManager {
|
||||
*/
|
||||
public void removePlatforms(int tenantId) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To get the platform tags.
|
||||
*
|
||||
* @param name Starting character sequence of the platform name.
|
||||
* @return list of the platform tags that start with the character sequence.
|
||||
* @throws PlatformManagementException PlatformManagement Exception
|
||||
*/
|
||||
public List<String> getPlatformTags(String name) throws PlatformManagementException;
|
||||
}
|
||||
|
||||
@ -54,4 +54,6 @@ public interface PlatformDAO {
|
||||
|
||||
int getMultiTenantPlatforms(String identifier) throws PlatformManagementDAOException;
|
||||
|
||||
List<String> getPlatformTags(String name) throws PlatformManagementDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -666,6 +666,39 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("SQL exception while executing the query " + sql + " to get the"
|
||||
+ " tenants which has the platform with the platform identifier : " + identifier, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlatformTags(String name) throws PlatformManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "";
|
||||
List<String> tagList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT NAME FROM APPM_PLATFORM_TAG WHERE NAME LIKE ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, name + "%");
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
tagList.add(rs.getString("NAME"));
|
||||
}
|
||||
return tagList;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Database Connection exception while trying to get the platform "
|
||||
+ "tags that are starting with " + name, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("SQL exception while executing the query " + sql + " to get the"
|
||||
+ " platform tags that are starting with " + name, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,6 +419,19 @@ public class PlatformManagerImpl implements PlatformManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlatformTags(String name) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return DAOFactory.getPlatformDAO().getPlatformTags(name);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementException("Database Connection Exception while getting the platform tags that"
|
||||
+ " are starting with the character sequence " + name, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To share the super-tenant platform with other tenants
|
||||
* @param platformIdentifier Identifier of the platform
|
||||
|
||||
@ -286,7 +286,7 @@ CREATE INDEX FK_APPLICATION_COMMENTS_APPLICATION_RELEASE ON APPM_COMMENT(APPLICA
|
||||
-- Table APPM_PLATFORM_TAG
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG (
|
||||
name VARCHAR(100) NOT NULL,
|
||||
NAME VARCHAR(100) NOT NULL,
|
||||
PLATFORM_ID INT NOT NULL,
|
||||
PRIMARY KEY (PLATFORM_ID, name),
|
||||
CONSTRAINT fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user