|
|
@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.Platform;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.PlatformStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.PlatformStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
@ -61,6 +62,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getPlatforms(@QueryParam("status") String status, @QueryParam("tag") String tag) {
|
|
|
|
public Response getPlatforms(@QueryParam("status") String status, @QueryParam("tag") String tag) {
|
|
|
|
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
PlatformStorageManager platformStorageManager = APIUtil.getPlatformStorageManager();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("API request received for getting the platforms with the status " + status);
|
|
|
|
log.debug("API request received for getting the platforms with the status " + status);
|
|
|
@ -92,25 +94,25 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
results = platforms;
|
|
|
|
results = platforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (results != null) {
|
|
|
|
if (tag != null) {
|
|
|
|
for (Platform platform : results) {
|
|
|
|
if (results != null) {
|
|
|
|
if (tag == null || tag.isEmpty() || (platform.getTags() != null && platform.getTags()
|
|
|
|
for (Platform platform : results) {
|
|
|
|
.contains(tag))) {
|
|
|
|
if (platform.getTags() != null && platform.getTags().contains(tag)) {
|
|
|
|
platform.setIcon(platformStorageManager.getIcon(platform.getIdentifier()));
|
|
|
|
filteredPlatforms.add(platform);
|
|
|
|
filteredPlatforms.add(platform);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
filteredPlatforms = results;
|
|
|
|
log.debug("Number of platforms with the status " + status + " : " + results.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Number of platforms with the status " + status + " : " + results.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(filteredPlatforms).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(filteredPlatforms).build();
|
|
|
|
} catch (PlatformManagementException e) {
|
|
|
|
} catch (PlatformManagementException e) {
|
|
|
|
log.error("Error while getting the platforms for tenant - " + tenantID, e);
|
|
|
|
log.error("Error while getting the platforms for tenant - " + tenantID, e);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
} catch (PlatformStorageManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error while getting platform icons for the tenant : " + tenantID, e);
|
|
|
|
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +128,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("Platform not found").build();
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("Platform not found").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImageArtifact icon = APIUtil.getPlatformStorageManager().getIcon(id);
|
|
|
|
ImageArtifact icon = APIUtil.getPlatformStorageManager().getIcon(id);
|
|
|
|
|
|
|
|
if (icon != null) {
|
|
|
|
|
|
|
|
platform.setIcon(icon);
|
|
|
|
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(platform).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(platform).build();
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
log.error("Error while trying the get the platform with the identifier : " + id + " for the tenant :"
|
|
|
|
log.error("Error while trying the get the platform with the identifier : " + id + " for the tenant :"
|
|
|
@ -137,8 +141,8 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
|
|
|
+ tenantId, e);
|
|
|
|
+ tenantId, e);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
|
|
|
} catch (PlatformStorageManagementException e) {
|
|
|
|
} catch (PlatformStorageManagementException e) {
|
|
|
|
log.error("Platform Storage Management Exception while trying to update the icon for the platform : " +
|
|
|
|
log.error("Platform Storage Management Exception while trying to update the icon for the platform : " + id
|
|
|
|
id + " for the tenant : " + tenantId, e);
|
|
|
|
+ " for the tenant : " + tenantId, e);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -205,8 +209,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
|
|
|
APIUtil.getPlatformManager().unregister(tenantId, id, false);
|
|
|
|
APIUtil.getPlatformManager().unregister(tenantId, id, false);
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
} catch (PlatformManagementException e) {
|
|
|
|
} catch (PlatformManagementException e) {
|
|
|
|
log.error("Platform Management Exception while trying to un-register the platform with the identifier : "
|
|
|
|
log.error(
|
|
|
|
+ id + " for the tenant : " + tenantId, e);
|
|
|
|
"Platform Management Exception while trying to un-register the platform with the identifier : " + id
|
|
|
|
|
|
|
|
+ " for the tenant : " + tenantId, e);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
|
|
} catch (PlatformStorageManagementException e) {
|
|
|
|
} catch (PlatformStorageManagementException e) {
|
|
|
|
log.error("Platform Storage Management Exception while trying to delete the icon of the platform with "
|
|
|
|
log.error("Platform Storage Management Exception while trying to delete the icon of the platform with "
|
|
|
|