forked from community/device-mgt-core
parent
dc6ab1db2f
commit
81be917e10
@ -1,417 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.api.services;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* API for handling platform related operations in application management.
|
||||
*/
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Platform Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "PlatformManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/platforms"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "device_management, application_management", description = "Platform Management APIS "
|
||||
+ "related with Application Management")
|
||||
}
|
||||
)
|
||||
@Scopes (
|
||||
scopes = {
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Get platform details",
|
||||
description = "Get platform details",
|
||||
key = "perm:platform:get",
|
||||
permissions = {"/device-mgt/platform/get"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Add a platform",
|
||||
description = "Add a platform",
|
||||
key = "perm:platform:add",
|
||||
permissions = {"/device-mgt/platform/add"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Update a platform",
|
||||
description = "Update a platform",
|
||||
key = "perm:platform:update",
|
||||
permissions = {"/device-mgt/platform/update"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Remove a platform",
|
||||
description = "Remove a platform",
|
||||
key = "perm:platform:remove",
|
||||
permissions = {"/device-mgt/platform/remove"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Api(value = "Platform Management", description = "This API carries all platform management related operations " +
|
||||
"such as get all the available platform for a tenant, etc.")
|
||||
@Path("/platforms")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface PlatformManagementAPI {
|
||||
String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get all platforms",
|
||||
notes = "This will get all platforms that is visible for tenants",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:get")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully got platforms list.",
|
||||
response = Platform.class,
|
||||
responseContainer = "List"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getPlatforms(
|
||||
@ApiParam(name = "status", allowableValues = "ENABLED, DISABLED, ALL", value =
|
||||
"Provide the status of platform for that tenant:\n"
|
||||
+ "- 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")
|
||||
@QueryParam("status")
|
||||
@Size(max = 45)
|
||||
String status,
|
||||
@ApiParam(name = "tag", defaultValue = "Tag value that we need to search the platform for")
|
||||
@QueryParam("tag") String tag
|
||||
);
|
||||
|
||||
@GET
|
||||
@Path("/{identifier}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get platform",
|
||||
notes = "This will return the platform which is registered with {identifier}",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:get")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully got requested platform.",
|
||||
response = Platform.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getPlatform(
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier
|
||||
);
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Add Platform",
|
||||
notes = "This will a platform for the tenant space",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:add")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully added the platform"),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request parameters passed."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response addPlatform(
|
||||
@Multipart(value = "Platform", type = "application/json") Platform platform,
|
||||
@Multipart(value = "icon", required = false) Attachment iconFile
|
||||
);
|
||||
|
||||
@PUT
|
||||
@Path("/{identifier}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Update Platform",
|
||||
notes = "This will update the platform configuration for the tenant space",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the platform"),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request parameters passed."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updatePlatform(
|
||||
@ApiParam(
|
||||
name = "platform",
|
||||
value = "The payload of the platform",
|
||||
required = true)
|
||||
Platform platform,
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier
|
||||
);
|
||||
|
||||
@DELETE
|
||||
@Path("/{identifier}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "DELETE",
|
||||
value = "Remove Platform",
|
||||
notes = "This will remove the relevant platform.",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:remove")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully deleted the platform"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while deleting the platform.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response removePlatform(
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier
|
||||
);
|
||||
|
||||
@PUT
|
||||
@Path("update-status/{identifier}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Update Platform status",
|
||||
notes = "This will update the platform status for the tenant space",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the platform."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not found. \n Non-file based platform not found to update."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the platform list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updatePlatformStatus(
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier,
|
||||
@ApiParam(name = "status", allowableValues = "ENABLED, DISABLED", value =
|
||||
"Provide the status of platform for that tenant:\n"
|
||||
+ "- ENABLED: The platforms that are currently enabled for the tenant\n"
|
||||
+ "- DISABLED: The platforms that currently disabled "
|
||||
+ "to be used for tenant\n", required = true)
|
||||
@QueryParam("status")
|
||||
String status
|
||||
);
|
||||
|
||||
@GET
|
||||
@Path("tags/{name}")
|
||||
@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)
|
||||
@PathParam("name") @Size(min = 3) String name
|
||||
);
|
||||
|
||||
@POST
|
||||
@Path("/{identifier}/icon")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.MULTIPART_FORM_DATA,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Update Platform icon",
|
||||
notes = "This will update the platform icon",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the platform icon"),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request parameters passed."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while updating the platform icon.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updatePlatformIcon(
|
||||
@ApiParam(
|
||||
name = "identifier",
|
||||
required = true)
|
||||
@PathParam("identifier")
|
||||
@Size(max = 45)
|
||||
String identifier,
|
||||
@Multipart(value = "icon") Attachment iconFile
|
||||
);
|
||||
}
|
@ -1,284 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.api.services.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.api.APIUtil;
|
||||
import org.wso2.carbon.device.application.mgt.api.services.PlatformManagementAPI;
|
||||
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
||||
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.PlatformStorageManagementException;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Implementation of PlatformManagement APIs.
|
||||
*/
|
||||
@Path("/platforms")
|
||||
public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
|
||||
private static final String ALL_STATUS = "ALL";
|
||||
private static final String ENABLED_STATUS = "ENABLED";
|
||||
private static final String DISABLED_STATUS = "DISABLED";
|
||||
|
||||
private static Log log = LogFactory.getLog(PlatformManagementAPIImpl.class);
|
||||
|
||||
@GET
|
||||
@Override
|
||||
public Response getPlatforms(@QueryParam("status") String status, @QueryParam("tag") String tag) {
|
||||
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
PlatformStorageManager platformStorageManager = APIUtil.getPlatformStorageManager();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("API request received for getting the platforms with the status " + status);
|
||||
}
|
||||
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;
|
||||
} else if (status.contentEquals(ENABLED_STATUS)) {
|
||||
results = new ArrayList<>();
|
||||
for (Platform platform : platforms) {
|
||||
if (platform.isEnabled()) {
|
||||
results.add(platform);
|
||||
}
|
||||
}
|
||||
} else if (status.contentEquals(DISABLED_STATUS)) {
|
||||
results = new ArrayList<>();
|
||||
for (Platform platform : platforms) {
|
||||
if (!platform.isEnabled()) {
|
||||
results.add(platform);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
results = platforms;
|
||||
}
|
||||
} else {
|
||||
results = platforms;
|
||||
}
|
||||
if (results != null) {
|
||||
for (Platform platform : results) {
|
||||
if (tag == null || tag.isEmpty() || (platform.getTags() != null && platform.getTags()
|
||||
.contains(tag))) {
|
||||
platform.setIcon(platformStorageManager.getIcon(platform.getIdentifier()));
|
||||
filteredPlatforms.add(platform);
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms with the status " + status + " : " + results.size());
|
||||
}
|
||||
}
|
||||
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);
|
||||
} catch (PlatformStorageManagementException e) {
|
||||
log.error("Error while getting platform icons for the tenant : " + tenantID, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Path("/{identifier}")
|
||||
public Response getPlatform(@PathParam("identifier") String id) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
Platform platform = APIUtil.getPlatformManager().getPlatform(tenantId, id);
|
||||
|
||||
if (platform == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Platform not found").build();
|
||||
}
|
||||
ImageArtifact icon = APIUtil.getPlatformStorageManager().getIcon(id);
|
||||
if (icon != null) {
|
||||
platform.setIcon(icon);
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(platform).build();
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
log.error("Error while trying the get the platform with the identifier : " + id + " for the tenant :"
|
||||
+ tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while trying the get the platform with the identifier : " + id + " for the tenant :"
|
||||
+ tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
} catch (PlatformStorageManagementException e) {
|
||||
log.error("Platform Storage Management Exception while trying to get the icon for the platform : " + id
|
||||
+ " for the tenant : " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Override
|
||||
public Response addPlatform(@Multipart("platform") Platform platform, @Multipart("icon")Attachment icon) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
if (platform != null) {
|
||||
if (platform.validate()) {
|
||||
APIUtil.getPlatformManager().register(tenantId, platform);
|
||||
|
||||
if (icon != null) {
|
||||
InputStream iconFileStream = icon.getDataHandler().getInputStream();
|
||||
APIUtil.getPlatformStorageManager().uploadIcon(platform.getIdentifier(), iconFileStream);
|
||||
}
|
||||
return Response.status(Response.Status.CREATED).build();
|
||||
} else {
|
||||
return APIUtil
|
||||
.getResponse("Invalid payload! Platform 'identifier' and 'name' are mandatory fields!",
|
||||
Response.Status.BAD_REQUEST);
|
||||
}
|
||||
} else {
|
||||
return APIUtil.getResponse("Invalid payload! Platform needs to be passed as payload!",
|
||||
Response.Status.BAD_REQUEST);
|
||||
}
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Platform Management Exception while trying to add the platform with identifier : " + platform
|
||||
.getIdentifier() + " for the tenant : " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (IOException e) {
|
||||
log.error("IO Exception while trying to save platform icon for the platform : " + platform.getIdentifier(),
|
||||
e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (ResourceManagementException e) {
|
||||
log.error("Storage Exception while trying to save platform icon for the platform : " + platform
|
||||
.getIdentifier(), e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{identifier}")
|
||||
@Override
|
||||
public Response updatePlatform(Platform platform, @PathParam("identifier") @Size(max = 45) String id) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
APIUtil.getPlatformManager().update(tenantId, id, platform);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{identifier}")
|
||||
@Override
|
||||
public Response removePlatform(@PathParam("identifier") @Size(max = 45) String id) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
APIUtil.getPlatformStorageManager().deleteIcon(id);
|
||||
APIUtil.getPlatformManager().unregister(tenantId, id, false);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error(
|
||||
"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);
|
||||
} catch (PlatformStorageManagementException e) {
|
||||
log.error("Platform Storage Management Exception while trying to delete the icon of the platform with "
|
||||
+ "identifier for the tenant :" + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("update-status/{identifier}")
|
||||
@Override
|
||||
public Response updatePlatformStatus(@PathParam("identifier") @Size(max = 45) String id, @QueryParam("status")
|
||||
String status) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
APIUtil.getPlatformManager().updatePlatformStatus(tenantId, id, status);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
log.error("Platform Management Database Exception while trying to update the status of the platform with "
|
||||
+ "the identifier : " + id + " for the tenant : " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Platform Management Exception while trying to update the status of the platform with the "
|
||||
+ "identifier : " + id + " for the tenant : " + tenantId, e);
|
||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("tags/{name}")
|
||||
@Override
|
||||
public Response getPlatformTags(@PathParam("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);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{identifier}/icon")
|
||||
@Override
|
||||
public Response updatePlatformIcon(@PathParam("identifier") String identifier, @Multipart("icon") Attachment
|
||||
icon) {
|
||||
try {
|
||||
if (icon != null) {
|
||||
InputStream iconFileStream = icon.getDataHandler().getInputStream();
|
||||
APIUtil.getPlatformStorageManager().uploadIcon(identifier, iconFileStream);
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Icon file is successfully updated for the platform :" + identifier).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("Icon file is not provided to update")
|
||||
.build();
|
||||
}
|
||||
} catch (ResourceManagementException e) {
|
||||
log.error("Resource Management exception while trying to update the icon for the platform " + identifier);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} catch (IOException e) {
|
||||
log.error("IO exception while trying to update the icon for the platform " + identifier);
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||
|
||||
/**
|
||||
* Represents the category a particular {@link Application} belongs to.
|
||||
*/
|
||||
public class Category {
|
||||
|
||||
@Exclude
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Application represents the an Application in Application Store.
|
||||
*/
|
||||
public class DeviceType {
|
||||
|
||||
@Exclude
|
||||
private int id;
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
|
||||
private Date lastUpdated;
|
||||
|
||||
private String providerTenantID;
|
||||
|
||||
private int sharedWithAllTenants;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public String getProviderTenantID() {
|
||||
return providerTenantID;
|
||||
}
|
||||
|
||||
public void setProviderTenantID(String providerTenantID) {
|
||||
this.providerTenantID = providerTenantID;
|
||||
}
|
||||
|
||||
public int getSharedWithAllTenants() {
|
||||
return sharedWithAllTenants;
|
||||
}
|
||||
|
||||
public void setSharedWithAllTenants(int sharedWithAllTenants) {
|
||||
this.sharedWithAllTenants = sharedWithAllTenants;
|
||||
}
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the platform of an {@link Application}.
|
||||
*/
|
||||
public class Platform {
|
||||
|
||||
/**
|
||||
* Unique id reference that is used in the database.
|
||||
*/
|
||||
@Exclude
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* The name of the platform. It can contain spaces,etc.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Unique human readable identifier used for the platform.
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
private String iconName;
|
||||
|
||||
private boolean fileBased;
|
||||
|
||||
private boolean shared;
|
||||
|
||||
private List<String> tags;
|
||||
|
||||
private List<Property> properties;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
private boolean defaultTenantMapping;
|
||||
|
||||
private ImageArtifact icon;
|
||||
|
||||
public Platform(Platform platform) {
|
||||
this.id = platform.getId();
|
||||
this.name = platform.getName();
|
||||
this.description = platform.getDescription();
|
||||
this.identifier = platform.getIdentifier();
|
||||
this.iconName = platform.getIconName();
|
||||
this.fileBased = platform.isFileBased();
|
||||
this.shared = platform.isShared();
|
||||
this.enabled = platform.isEnabled();
|
||||
this.defaultTenantMapping = platform.isDefaultTenantMapping();
|
||||
if (platform.getProperties() != null) {
|
||||
this.properties = new ArrayList<>();
|
||||
for (Property property : platform.getProperties()) {
|
||||
this.properties.add(new Property(property));
|
||||
}
|
||||
}
|
||||
if (platform.getTags() != null) {
|
||||
this.tags = new ArrayList<>();
|
||||
for (String tag : platform.getTags()) {
|
||||
this.tags.add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Platform() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIconName() {
|
||||
return iconName;
|
||||
}
|
||||
|
||||
public void setIconName(String iconName) {
|
||||
this.iconName = iconName;
|
||||
}
|
||||
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public boolean isFileBased() {
|
||||
return fileBased;
|
||||
}
|
||||
|
||||
public void setFileBased(boolean fileBased) {
|
||||
this.fileBased = fileBased;
|
||||
}
|
||||
|
||||
public boolean isShared() {
|
||||
return shared;
|
||||
}
|
||||
|
||||
public void setShared(boolean shared) {
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isDefaultTenantMapping() {
|
||||
return defaultTenantMapping;
|
||||
}
|
||||
|
||||
public void setDefaultTenantMapping(boolean defaultTenantMapping) {
|
||||
this.defaultTenantMapping = defaultTenantMapping;
|
||||
}
|
||||
|
||||
public boolean validate() {
|
||||
return !(name == null || identifier == null);
|
||||
}
|
||||
|
||||
public void setIcon(ImageArtifact icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a property of a {@link Platform}.
|
||||
*/
|
||||
public static class Property implements Cloneable {
|
||||
|
||||
private String name;
|
||||
private boolean optional;
|
||||
private String defaultValue;
|
||||
|
||||
public Property(Property property) {
|
||||
this.name = property.getName();
|
||||
this.optional = property.isOptional();
|
||||
this.defaultValue = property.getDefaultValue();
|
||||
}
|
||||
|
||||
public Property() {
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public void setOptional(boolean optional) {
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/UnrestrictedRoles.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/UnrestrictedRole.java
22
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/UnrestrictedRoles.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/UnrestrictedRole.java
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception caused during the platform management.
|
||||
*/
|
||||
public class PlatformManagementException extends ApplicationManagementException {
|
||||
|
||||
public PlatformManagementException(String message, Throwable ex) {
|
||||
super(message, ex);
|
||||
}
|
||||
|
||||
public PlatformManagementException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Represents the exception thrown during storing and retrieving those artifacts.
|
||||
*/
|
||||
public class PlatformStorageManagementException extends ResourceManagementException {
|
||||
public PlatformStorageManagementException(String message, Throwable ex) {
|
||||
super(message, ex);
|
||||
}
|
||||
|
||||
public PlatformStorageManagementException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Platform manager is responsible for handling platforms, which will be used to as a registry of platforms.
|
||||
* And will be able to provide the platforms related information to other classes which requires.
|
||||
*/
|
||||
public interface PlatformManager {
|
||||
|
||||
/**
|
||||
* To initialize the shared platforms for the tenant during the tenant initialization time.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
void initialize(int tenantId) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To get platforms of the specific tenant.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @return List of platforms
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
List<Platform> getPlatforms(int tenantId) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To get platform with the given platform identifier and tenant ID.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param platformIdentifier Unique identifier of the platform.
|
||||
* @return the Specific platform with the platform identifier and tenant
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To register a platform under particular tenant.
|
||||
*
|
||||
* @param tenantId ID of the tenant.
|
||||
* @param platform Platform to be registered
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
void register(int tenantId, Platform platform) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To update a platform.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param oldPlatformIdentifier Old platform Identifier
|
||||
* @param platform Platform to be updated
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To un-register the platform.
|
||||
*
|
||||
* @param tenantId ID of the tenant.
|
||||
* @param platformIdentifier ID of the platform
|
||||
* @param isFileBased To indicate whether a file based or not.
|
||||
* @throws PlatformManagementException Platform Management Exception.
|
||||
*/
|
||||
void unregister(int tenantId, String platformIdentifier, boolean isFileBased) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To add mapping to platform identifiers with the tenant ID.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param platformIdentifiers Platform Identifiers
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To add mapping to a platform for a tenant.
|
||||
*
|
||||
* @param tenantId ID of the tenant.
|
||||
* @param platformIdentifier ID of the platform, the mapping should be added.
|
||||
* @throws PlatformManagementException Platform Management Exception.
|
||||
*/
|
||||
void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To remove a mapping of a platform to a tenant.
|
||||
*
|
||||
* @param tenantId ID of the tenant.
|
||||
* @param platformIdentifier ID of the platform.
|
||||
* @throws PlatformManagementException Platform Management Exception.
|
||||
*/
|
||||
void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To update the platform status(ENABLED / DISABLED).
|
||||
*
|
||||
* @param tenantId Id of the tenant
|
||||
* @param platformIdentifier ID of the platform
|
||||
* @param status Status to be updated.
|
||||
* @throws PlatformManagementException Platform Management Exception.
|
||||
*/
|
||||
void updatePlatformStatus(int tenantId, String platformIdentifier, String status)
|
||||
throws PlatformManagementException;
|
||||
|
||||
/**
|
||||
* To remove platforms that belongs to particular tenant.
|
||||
*
|
||||
* @param tenantId ID of the tenant.
|
||||
* @throws PlatformManagementException Platform Management Exception.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
List<String> getPlatformTags(String name) throws PlatformManagementException;
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformStorageManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* This class manages all the storage related requirements of Platform.
|
||||
*/
|
||||
public interface PlatformStorageManager {
|
||||
/**
|
||||
* To upload image artifacts related with an Application.
|
||||
*
|
||||
* @param platformIdentifier Identifier of the platform
|
||||
* @param iconFile Icon File input stream
|
||||
* @throws ResourceManagementException Resource Management Exception.
|
||||
*/
|
||||
void uploadIcon(String platformIdentifier, InputStream iconFile) throws ResourceManagementException;
|
||||
|
||||
/**
|
||||
* To get the icon for a particular platform.
|
||||
*
|
||||
* @param platformIdentifier Identifier of the platform.
|
||||
* @return the icon for the given platform.
|
||||
* @throws PlatformStorageManagementException Platform Storage Management Exception.
|
||||
*/
|
||||
ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException;
|
||||
|
||||
/**
|
||||
* To delete the icon of a particular platform
|
||||
*
|
||||
* @param platformIdentifier Identifier of the platform to which delete icon.
|
||||
* @throws PlatformStorageManagementException PlatformStorageManagement Exception.
|
||||
*/
|
||||
void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Category;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is responsible for Application Category related DAO operations.
|
||||
*/
|
||||
public interface CategoryDAO {
|
||||
|
||||
/**
|
||||
* To add a new category.
|
||||
*
|
||||
* @param category Category that need to be added.
|
||||
* @return Newly added category.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
Category addCategory(Category category) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* To get the existing categories.
|
||||
*
|
||||
* @return Existing categories.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
List<Category> getCategories() throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* To get the category with the given name.
|
||||
*
|
||||
* @param name Name of the Application category.
|
||||
* @return Application Category.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
Category getCategory(String name) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* To delete a particular category.
|
||||
*
|
||||
* @param name Name of the category that need to be deleted.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
void deleteCategory(String name) throws ApplicationManagementDAOException;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* /
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
|
||||
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is responsible for all the DAO operations related to Lifecycle state.
|
||||
*/
|
||||
public interface LifecycleDAO {
|
||||
|
||||
Lifecycle getLifeCycleOfApplication(int identifier) throws LifeCycleManagementDAOException;
|
||||
|
||||
List<Lifecycle> getLifecyclesOfAllAppVersions (int identifier) throws LifeCycleManagementDAOException;
|
||||
|
||||
void addLifecycle(Lifecycle lifecycle) throws LifeCycleManagementDAOException;
|
||||
|
||||
void updateLifecycleOfApplication(LifecycleState state) throws LifeCycleManagementDAOException;
|
||||
|
||||
void deleteLifecycleOfApplication(String identifier) throws LifeCycleManagementDAOException;
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PlatformDAO defines set of DAO operations that are needed for Platform Management.
|
||||
*/
|
||||
public interface PlatformDAO {
|
||||
|
||||
int register(int tenantId, Platform platform) throws PlatformManagementDAOException;
|
||||
|
||||
void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException;
|
||||
|
||||
void unregister(int tenantId, String platformIdentifier, boolean isFileBased) throws PlatformManagementDAOException;
|
||||
|
||||
void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException;
|
||||
|
||||
void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException;
|
||||
|
||||
void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException;
|
||||
|
||||
List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException;
|
||||
|
||||
Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException;
|
||||
|
||||
Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException;
|
||||
|
||||
void removePlatforms(int tenantId) throws PlatformManagementDAOException;
|
||||
|
||||
int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId) throws PlatformManagementDAOException;
|
||||
|
||||
Platform getTenantOwnedPlatform(int tenantId, String platformIdentifier) throws PlatformManagementDAOException;
|
||||
|
||||
int getMultiTenantPlatforms(String identifier) throws PlatformManagementDAOException;
|
||||
|
||||
List<String> getPlatformTags(String name) throws PlatformManagementDAOException;
|
||||
|
||||
}
|
62
components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java → components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java
62
components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java → components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java
@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.category;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Category;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the concrete implementation of {@link CategoryDAO}.
|
||||
*/
|
||||
public class GenericCategoryDAOImpl extends AbstractDAOImpl implements CategoryDAO {
|
||||
@Override
|
||||
public Category addCategory(Category category) throws ApplicationManagementDAOException {
|
||||
Connection connection;
|
||||
PreparedStatement statement = null;
|
||||
String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)";
|
||||
String[] generatedColumns = { "ID" };
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql, generatedColumns);
|
||||
statement.setString(1, category.getName());
|
||||
statement.setString(2, category.getDescription());
|
||||
statement.executeUpdate();
|
||||
rs = statement.getGeneratedKeys();
|
||||
if (rs.next()) {
|
||||
category.setId(rs.getInt(1));
|
||||
}
|
||||
return category;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"Database connection while trying to update the categroy " + category.getName(), e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e);
|
||||
} finally {
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Category> getCategories() throws ApplicationManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY";
|
||||
List<Category> categories = new ArrayList<>();
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
stmt = conn.prepareStatement(sql);
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Category category = new Category();
|
||||
category.setId(rs.getInt("ID"));
|
||||
category.setName(rs.getString("NAME"));
|
||||
category.setDescription(rs.getString("DESCRIPTION"));
|
||||
categories.add(category);
|
||||
}
|
||||
return categories;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
|
||||
+ "application categories", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
|
||||
+ "categories, while executing " + sql, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getCategory(String name) throws ApplicationManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, name);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
Category category = new Category();
|
||||
category.setId(rs.getInt("ID"));
|
||||
category.setName(rs.getString("NAME"));
|
||||
category.setDescription(rs.getString("DESCRIPTION"));
|
||||
return category;
|
||||
}
|
||||
return null;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
|
||||
+ "application categories", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
|
||||
+ "categories, while executing " + sql, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCategory(String name) throws ApplicationManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, name);
|
||||
stmt.executeUpdate();
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"Database Connection Exception while trying to delete the category " + name, e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"SQL Exception while trying to delete the category " + name + " while executing the query " +
|
||||
sql, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* /
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecycle;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
|
||||
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Concrete implementation for Lifecycle related DB operations.
|
||||
*/
|
||||
public class GenericLifecycleImpl extends AbstractDAOImpl implements LifecycleDAO {
|
||||
|
||||
@Override
|
||||
public Lifecycle getLifeCycleOfApplication(int identifier) throws LifeCycleManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql = "SELECT ID, CREATED_BY, CREATED_TIMESTAMP, APPROVED, APPROVED_TIMESTAMP, APPROVED_BY, "
|
||||
+ "PUBLISHED, PUBLISHED_BY, PUBLISHED_TIMESTAMP, RETIRED FROM AP_APP_LIFECYCLE WHERE "
|
||||
+ "AP_APP_RELEASE_ID = ? ";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, identifier);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
Lifecycle lifecycle = null;
|
||||
|
||||
if (rs.next()) {
|
||||
lifecycle = new Lifecycle();
|
||||
lifecycle.setId(rs.getInt("ID"));
|
||||
lifecycle.setCreatedBy(rs.getString("CREATED_BY"));
|
||||
lifecycle.setCreatedAt(rs.getDate("CREATED_TIMESTAMP"));
|
||||
lifecycle.setIsApproved(rs.getInt("APPROVED"));
|
||||
lifecycle.setApprovedAt(rs.getDate("APPROVED_TIMESTAMP"));
|
||||
lifecycle.setApprovedBy(rs.getString("APPROVED_BY"));
|
||||
lifecycle.setIsPublished(rs.getInt("PUBLISHED"));
|
||||
lifecycle.setPublishedBy(rs.getString("PUBLISHED_BY"));
|
||||
lifecycle.setPublishedAt(rs.getDate("PUBLISHED_TIMESTAMP"));
|
||||
lifecycle.setIsRetired(rs.getInt("RETIRED"));
|
||||
}
|
||||
return lifecycle;
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while getting application List", e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Lifecycle> getLifecyclesOfAllAppVersions(int identifier) throws LifeCycleManagementDAOException {
|
||||
List<Lifecycle> lifecycles = new ArrayList<>();
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql = "SELECT ID, CREATED_BY, CREATED_TIMESTAMP, APPROVED, APPROVED_TIMESTAMP, APPROVED_BY, "
|
||||
+ "PUBLISHED, PUBLISHED_BY, PUBLISHED_TIMESTAMP, RETIRED FROM AP_APP_LIFECYCLE WHERE "
|
||||
+ "AP_APP_ID = ? ";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, identifier);
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Lifecycle lifecycle = new Lifecycle();
|
||||
lifecycle.setId(rs.getInt("ID"));
|
||||
lifecycle.setCreatedBy(rs.getString("CREATED_BY"));
|
||||
lifecycle.setCreatedAt(rs.getDate("CREATED_TIMESTAMP"));
|
||||
lifecycle.setIsApproved(rs.getInt("APPROVED"));
|
||||
lifecycle.setApprovedAt(rs.getDate("APPROVED_TIMESTAMP"));
|
||||
lifecycle.setApprovedBy(rs.getString("APPROVED_BY"));
|
||||
lifecycle.setIsPublished(rs.getInt("PUBLISHED"));
|
||||
lifecycle.setPublishedBy(rs.getString("PUBLISHED_BY"));
|
||||
lifecycle.setPublishedAt(rs.getDate("PUBLISHED_TIMESTAMP"));
|
||||
lifecycle.setIsRetired(rs.getInt("RETIRED"));
|
||||
lifecycles.add(lifecycle);
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while retrieving lifecycle states.", e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
return lifecycles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLifecycle(Lifecycle lifecycle) throws LifeCycleManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql = "INSERT INTO AP_APP_LIFECYCLE ('CREATED_BY', 'CREATED_TIMESTAMP') VALUES (?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, lifecycle.getCreatedBy());
|
||||
stmt.setDate(2, new Date(lifecycle.getCreatedAt().getTime()));
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (DBConnectionException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle ", e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
// have to modify
|
||||
|
||||
@Override
|
||||
public void updateLifecycleOfApplication(LifecycleState state) throws LifeCycleManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql = "INSERT INTO APPM_LIFECYCLE_STATE ('NAME', 'IDENTIFIER',) VALUES (?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, state.getName());
|
||||
stmt.setString(2, state.getIdentifier());
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (DBConnectionException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getIdentifier(), e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLifecycleOfApplication(String identifier) throws LifeCycleManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql = "DELETE FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, identifier);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (DBConnectionException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new LifeCycleManagementDAOException("Error occurred while deleting lifecycle: " + identifier, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
// end modification
|
||||
}
|
@ -1,703 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.platform;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Generic Implementation for handling Platform management related database operations.
|
||||
*/
|
||||
public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
|
||||
private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int register(int tenantId, Platform platform) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
int platformId = getPlatformId(tenantId, platform.getIdentifier());
|
||||
if (platformId == -1) {
|
||||
Connection connection = this.getDBConnection();
|
||||
if (!platform.isFileBased()) {
|
||||
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, NAME, FILE_BASED, "
|
||||
+ "DESCRIPTION, IS_SHARED, ICON_NAME, IS_DEFAULT_TENANT_MAPPING)" + " VALUES (?, ?, ?, ?, "
|
||||
+ "?, ?, ?, ?)";
|
||||
preparedStatement = connection.prepareStatement(insertToPlatform);
|
||||
preparedStatement.setString(1, platform.getIdentifier());
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
preparedStatement.setString(3, platform.getName());
|
||||
preparedStatement.setBoolean(4, false);
|
||||
preparedStatement.setString(5, platform.getDescription());
|
||||
preparedStatement.setBoolean(6, platform.isShared());
|
||||
preparedStatement.setString(7, platform.getIconName());
|
||||
preparedStatement.setBoolean(8, platform.isDefaultTenantMapping());
|
||||
preparedStatement.execute();
|
||||
|
||||
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
||||
String insertPlatformProps =
|
||||
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, "
|
||||
+ "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
||||
|
||||
if (platform.getProperties() != null) {
|
||||
for (Platform.Property property : platform.getProperties()) {
|
||||
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
||||
preparedStatement.setInt(1, platformId);
|
||||
preparedStatement.setString(2, property.getName());
|
||||
preparedStatement.setBoolean(3, property.isOptional());
|
||||
preparedStatement.setString(4, property.getDefaultValue());
|
||||
preparedStatement.execute();
|
||||
}
|
||||
}
|
||||
//Adding tags to the database.
|
||||
Boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
|
||||
String insertTags = "INSERT INTO APPM_PLATFORM_TAG (NAME, PLATFORM_ID) VALUES (?, ?)";
|
||||
preparedStatement = connection.prepareStatement(insertTags);
|
||||
if (platform.getTags() != null) {
|
||||
for (String tag : platform.getTags()) {
|
||||
preparedStatement.setString(1, tag);
|
||||
preparedStatement.setInt(2, platformId);
|
||||
|
||||
if (isBatchExecutionSupported) {
|
||||
preparedStatement.addBatch();
|
||||
} else {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
}
|
||||
if (isBatchExecutionSupported) {
|
||||
preparedStatement.executeBatch();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String insertToPlatform =
|
||||
"INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED, IS_SHARED, "
|
||||
+ "IS_DEFAULT_TENANT_MAPPING) VALUES (?, ?, ?, ?, ?)";
|
||||
preparedStatement = connection.prepareStatement(insertToPlatform);
|
||||
preparedStatement.setString(1, platform.getIdentifier());
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
preparedStatement.setBoolean(3, true);
|
||||
preparedStatement.setBoolean(4, platform.isShared());
|
||||
preparedStatement.setBoolean(5, platform.isDefaultTenantMapping());
|
||||
preparedStatement.execute();
|
||||
}
|
||||
if (platformId == -1) {
|
||||
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
||||
}
|
||||
return platformId;
|
||||
} else {
|
||||
if (!platform.isFileBased()) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Platform - " + platform.getIdentifier() + " is already registered for tenant - "
|
||||
+ tenantId);
|
||||
} else {
|
||||
return platformId;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Unable to obtain the connection while trying to register the platform - " + platform
|
||||
.getIdentifier() + " for tenant - " + tenantId, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int tenantId, String oldPlatformIdentifier, Platform platform)
|
||||
throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
int platformId = getPlatformId(tenantId, oldPlatformIdentifier);
|
||||
boolean isIdentifierNull = platform.getIdentifier() == null;
|
||||
boolean isNameNull = platform.getName() == null;
|
||||
|
||||
if (platformId != -1) {
|
||||
Connection connection = this.getDBConnection();
|
||||
if (!platform.isFileBased()) {
|
||||
String insertToPlatform = "UPDATE APPM_PLATFORM SET DESCRIPTION=?, IS_SHARED=?, ICON_NAME=?, "
|
||||
+ "IS_DEFAULT_TENANT_MAPPING=?";
|
||||
if (!isIdentifierNull) {
|
||||
insertToPlatform += ",IDENTIFIER = ? ";
|
||||
}
|
||||
if (!isNameNull) {
|
||||
insertToPlatform += ", NAME =?";
|
||||
}
|
||||
insertToPlatform += " WHERE ID = ?";
|
||||
preparedStatement = connection.prepareStatement(insertToPlatform);
|
||||
preparedStatement.setString(1, platform.getDescription());
|
||||
preparedStatement.setBoolean(2, platform.isShared());
|
||||
preparedStatement.setString(3, platform.getIconName());
|
||||
preparedStatement.setBoolean(4, platform.isDefaultTenantMapping());
|
||||
|
||||
if (!isIdentifierNull && !isNameNull) {
|
||||
preparedStatement.setString(5, platform.getIdentifier());
|
||||
preparedStatement.setString(6, platform.getName());
|
||||
preparedStatement.setInt(7, platformId);
|
||||
} else if (isIdentifierNull && !isNameNull) {
|
||||
preparedStatement.setString(5, platform.getName());
|
||||
preparedStatement.setInt(6, platformId);
|
||||
} else if (!isIdentifierNull) {
|
||||
preparedStatement.setString(5, platform.getIdentifier());
|
||||
preparedStatement.setInt(6, platformId);
|
||||
} else {
|
||||
preparedStatement.setInt(5, platformId);
|
||||
}
|
||||
preparedStatement.execute();
|
||||
|
||||
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
||||
String deletePlatformProps = "DELETE FROM APPM_PLATFORM_PROPERTIES WHERE PLATFORM_ID=?";
|
||||
preparedStatement = connection.prepareStatement(deletePlatformProps);
|
||||
preparedStatement.setInt(1, platformId);
|
||||
preparedStatement.execute();
|
||||
|
||||
String insertPlatformProps =
|
||||
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL,"
|
||||
+ " DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
||||
|
||||
if (platform.getProperties() != null) {
|
||||
for (Platform.Property property : platform.getProperties()) {
|
||||
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
||||
preparedStatement.setInt(1, platformId);
|
||||
preparedStatement.setString(2, property.getName());
|
||||
preparedStatement.setBoolean(3, property.isOptional());
|
||||
preparedStatement.setString(4, property.getDefaultValue());
|
||||
preparedStatement.execute();
|
||||
}
|
||||
}
|
||||
} else if (!isIdentifierNull) {
|
||||
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?";
|
||||
preparedStatement = connection.prepareStatement(insertToPlatform);
|
||||
preparedStatement.setString(1, platform.getIdentifier());
|
||||
preparedStatement.setInt(2, platformId);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
} else {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Cannot find any platform that was registered with identifier - " + platform.getIdentifier()
|
||||
+ " for tenant - " + tenantId);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Unable to obtain the connection while trying to register the platform - " + platform
|
||||
.getIdentifier() + " for tenant - " + tenantId, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
private int getPlatformId(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
String query = SQLQueries.queryToGetPlatformId;
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
preparedStatement.setString(2, platformIdentifier);
|
||||
preparedStatement.setString(3, platformIdentifier);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt("ID");
|
||||
}
|
||||
return -1;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Error when trying to obtaining the database connection.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error in executing the query - " + query, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(int tenantId, String platformIdenfier, boolean isFileBased)
|
||||
throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
String deletePlatform = null;
|
||||
try {
|
||||
Platform platform = getPlatform(tenantId, platformIdenfier);
|
||||
|
||||
if (platform != null) {
|
||||
if (isFileBased == platform.isFileBased()) {
|
||||
Connection connection = this.getDBConnection();
|
||||
deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
||||
preparedStatement = connection.prepareStatement(deletePlatform);
|
||||
preparedStatement.setInt(1, platform.getId());
|
||||
preparedStatement.execute();
|
||||
} else {
|
||||
if (isFileBased) {
|
||||
throw new PlatformManagementDAOException("Platform with identifier - " + platformIdenfier
|
||||
+ " is not a file based platform. Try to remove that using PlatformManagement APIs");
|
||||
} else {
|
||||
throw new PlatformManagementDAOException("Platform with identifier - " + platformIdenfier
|
||||
+ " is a file based platform. Try to remove that by un-deploying the relevant file.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Platform identifier - " + platformIdenfier + " is not registered for tenant - " + tenantId);
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Unable to obtain the connection while trying to register the platform - " + platformIdenfier
|
||||
+ " for tenant - " + tenantId, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error while executing the SQL query : " + deletePlatform + " "
|
||||
+ "while trying to un-register the platform with identifier " + platformIdenfier, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException {
|
||||
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_ID, PLATFORM_ID) VALUES (?, ?)";
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
for (String platformIdentifier : platformIdentifiers) {
|
||||
if (getTenantPlatformMapping(tenantId, platformIdentifier) == -1) {
|
||||
int platformId = getPlatformId(tenantId, platformIdentifier);
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(insertMapping);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
preparedStatement.setInt(2, platformId);
|
||||
preparedStatement.execute();
|
||||
} else {
|
||||
log.error("Platform identifier - " + platformIdentifier + " is already assigned to tenant domain"
|
||||
+ " - " + tenantId);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred when getting the connection for the database. ",
|
||||
e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + insertMapping,
|
||||
e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTenantPlatformMapping(int tenantId, String platformIdentifier)
|
||||
throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID, PLATFORM_ID FROM APPM_PLATFORM_TENANT_MAPPING "
|
||||
+ "WHERE TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
|
||||
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(getMapping);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
preparedStatement.setString(2, platformIdentifier);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt("ID");
|
||||
}
|
||||
return -1;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
||||
e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
|
||||
String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?";
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier);
|
||||
if (mappingId != -1) {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(deleteMapping);
|
||||
preparedStatement.setInt(1, mappingId);
|
||||
preparedStatement.execute();
|
||||
} else {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Platform - " + platformIdentifier + " is already unassigned for tenant - " + tenantId);
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred while unassigning the platform - " + platformIdentifier + " for tenant - "
|
||||
+ tenantId);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier);
|
||||
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?";
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(getMapping);
|
||||
preparedStatement.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
|
||||
preparedStatement.setInt(2, platformId);
|
||||
preparedStatement.execute();
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred while obtaining the connection to remove existing " + "Tenant - Platform Mapping"
|
||||
+ " for the platform : " + platformIdentifier, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred while executing the SQL query - " + getMapping, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("GetPlaforms request received for the tenant ID " + tenantId);
|
||||
}
|
||||
String selectQuery = SQLQueries.queryToGetPlatforms;
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(selectQuery);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
List<Platform> platforms = new ArrayList<>();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform retrieved for the tenant Id " + tenantId);
|
||||
}
|
||||
while (resultSet.next()) {
|
||||
int mappingID = resultSet.getInt(1);
|
||||
String identifier = resultSet.getString(2);
|
||||
Platform platform = getPlatform(tenantId, identifier);
|
||||
if (mappingID != 0) {
|
||||
platform.setEnabled(true);
|
||||
} else {
|
||||
platform.setEnabled(false);
|
||||
}
|
||||
platforms.add(platform);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Identifier - " + identifier + " isEnabled - " + platform.isEnabled());
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms available for the tenant ID - " + tenantId + " :" + platforms.size());
|
||||
}
|
||||
return platforms;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred when loading the platforms for tenant - " + tenantId, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
public Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) "
|
||||
+ "OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM "
|
||||
+ "LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(platformQuery);
|
||||
preparedStatement.setString(1, tenantDomain);
|
||||
preparedStatement.setString(2, platformIdentifier);
|
||||
preparedStatement.setString(3, platformIdentifier);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
Platform platform = new Platform();
|
||||
if (resultSet.next()) {
|
||||
platform.setId(resultSet.getInt("PLATFORM.ID"));
|
||||
platform.setIdentifier(platformIdentifier);
|
||||
platform.setName(resultSet.getString("PLATFORM.NAME"));
|
||||
platform.setIconName(resultSet.getString("PLATFORM.DESCRIPTION"));
|
||||
platform.setIconName(resultSet.getString("PLATFORM.ICON_NAME"));
|
||||
platform.setShared(resultSet.getBoolean("PLATFORM.IS_SHARED"));
|
||||
platform.setFileBased(false);
|
||||
List<Platform.Property> properties = new ArrayList<>();
|
||||
do {
|
||||
if (resultSet.getString("PROPS.PROP_NAME") != null) {
|
||||
Platform.Property property = new Platform.Property();
|
||||
property.setName(resultSet.getString("PROPS.PROP_NAME"));
|
||||
property.setOptional(resultSet.getBoolean("PROPS.OPTIONAL"));
|
||||
property.setDefaultValue(resultSet.getString("PROPS.DEFAUL_VALUE"));
|
||||
properties.add(property);
|
||||
}
|
||||
} while (resultSet.next());
|
||||
platform.setProperties(properties);
|
||||
} else {
|
||||
platform.setIdentifier(platformIdentifier);
|
||||
platform.setFileBased(true);
|
||||
}
|
||||
return platform;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Error when loading the platform - " + platformIdentifier, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error in executing the query - " + platformQuery, e);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "";
|
||||
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = SQLQueries.queryToGetPlatform;
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, identifier);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setInt(3, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
Platform platform = null;
|
||||
|
||||
if (rs.next()) {
|
||||
platform = new Platform();
|
||||
platform.setFileBased(rs.getBoolean(3));
|
||||
platform.setIdentifier(rs.getString(2));
|
||||
platform.setShared(rs.getBoolean(8));
|
||||
platform.setDefaultTenantMapping(rs.getBoolean(9));
|
||||
platform.setId(rs.getInt(4));
|
||||
//Getting tags
|
||||
sql = "SELECT * FROM APPM_PLATFORM_TAG WHERE PLATFORM_ID=?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, rs.getInt(4));
|
||||
ResultSet rsTags = stmt.executeQuery();
|
||||
|
||||
List<String> tags = new ArrayList<>();
|
||||
while (rsTags.next()) {
|
||||
tags.add(rsTags.getString("NAME"));
|
||||
}
|
||||
platform.setTags(tags);
|
||||
|
||||
if (!platform.isFileBased()) {
|
||||
platform.setName(rs.getString(5));
|
||||
platform.setDescription(rs.getString(6));
|
||||
platform.setIconName(rs.getString(7));
|
||||
if (rs.getInt(1) != 0) {
|
||||
platform.setEnabled(true);
|
||||
} else {
|
||||
platform.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return platform;
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred while getting platform with the identifier " + identifier + ", for the tenant : "
|
||||
+ tenantId, e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlatforms(int tenantId) throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
String sql = "DELETE FROM APPM_PLATFORM WHERE TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database connection error while removing the platforms for the " + "tenant - " + tenantId);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"SQL exception while executing the query " + sql + " for " + "the tenant : " + tenantId);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId)
|
||||
throws PlatformManagementDAOException {
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
String sql = SQLQueries.queryToGetSupertenantAndOwnPlatforms;
|
||||
|
||||
try {
|
||||
Connection connection = this.getDBConnection();
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, platformIdentifier);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
preparedStatement.setInt(3, MultitenantConstants.SUPER_TENANT_ID);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database connection error while removing the platfor for the " + "tenant - " + tenantId);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"SQL exception while executing the query " + sql + " for " + "the tenant : " + tenantId);
|
||||
} finally {
|
||||
Util.cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getTenantOwnedPlatform(int tenantId, String platformIdentifier)
|
||||
throws PlatformManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "";
|
||||
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT * from APPM_PLATFORM WHERE TENANT_ID = ? AND IDENTIFIER = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, platformIdentifier);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
Platform platform = null;
|
||||
|
||||
if (rs.next()) {
|
||||
platform = new Platform();
|
||||
platform.setFileBased(rs.getBoolean("FILE_BASED"));
|
||||
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
||||
platform.setShared(rs.getBoolean("IS_SHARED"));
|
||||
platform.setDefaultTenantMapping(rs.getBoolean("IS_DEFAULT_TENANT_MAPPING"));
|
||||
if (!platform.isFileBased()) {
|
||||
platform.setId(rs.getInt("ID"));
|
||||
platform.setName(rs.getString("NAME"));
|
||||
platform.setDescription(rs.getString("DESCRIPTION"));
|
||||
platform.setIconName(rs.getString("ICON_NAME"));
|
||||
}
|
||||
}
|
||||
return platform;
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occurred while executing the query : " + sql + " for "
|
||||
+ "getting platforms owned by tenant : " + tenantId, e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occurred while obtaining the DB connection for getting " + "platforms owned by tenant : "
|
||||
+ tenantId, e);
|
||||
} finally {
|
||||
Util.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMultiTenantPlatforms(String identifier) throws PlatformManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "";
|
||||
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT ID from APPM_PLATFORM WHERE TENANT_ID != ? AND IDENTIFIER=?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
|
||||
stmt.setString(2, identifier);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
return -1;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Database Connection exception while trying to get the tenants "
|
||||
+ "which has the platforms with the platform identifier : " + identifier, e);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.platform;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Oracle and MsSQL specific implementation for Platform DAO.
|
||||
*/
|
||||
public class OracleMsSQLPlatformDAOImpl extends GenericPlatformDAOImpl {
|
||||
|
||||
@Override
|
||||
public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId)
|
||||
throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetSupertenantAndOwnPlatforms = "SELECT ID from APPM_PLATFORM where IDENTIFIER "
|
||||
+ "= ? AND (TENANT_ID = ? OR (TENANT_ID = ? AND IS_SHARED = 1))";
|
||||
return super.getSuperTenantAndOwnPlatforms(platformIdentifier, tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int register(int tenantId, Platform platform) throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatformId =
|
||||
"SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND "
|
||||
+ "IDENTIFIER=?)";
|
||||
return super.register(tenantId, platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatform =
|
||||
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER, PLATFORM.FILE_BASED, PLATFORM.ID, PLATFORM.NAME, "
|
||||
+ "PLATFORM.DESCRIPTION, PLATFORM.ICON_NAME, PLATFORM.IS_SHARED, "
|
||||
+ "PLATFORM.IS_DEFAULT_TENANT_MAPPING FROM (SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER= ? "
|
||||
+ "AND (TENANT_ID=? OR IS_SHARED = 1)) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
||||
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?";
|
||||
return super.getPlatform(tenantId, identifier);
|
||||
}
|
||||
|
||||
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatformId =
|
||||
"SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND "
|
||||
+ "IDENTIFIER=?)";
|
||||
super.removeMappingTenants(platformIdentifier);
|
||||
}
|
||||
|
||||
public void update(int tenantId, String oldPlatformIdentifier, Platform platform)
|
||||
throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatformId =
|
||||
"SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND "
|
||||
+ "IDENTIFIER=?)";
|
||||
super.update(tenantId, oldPlatformIdentifier, platform);
|
||||
}
|
||||
|
||||
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatformId =
|
||||
"SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = 1 AND "
|
||||
+ "IDENTIFIER=?)";
|
||||
super.addMapping(tenantId, platformIdentifiers);
|
||||
}
|
||||
|
||||
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
|
||||
SQLQueries.queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM "
|
||||
+ "WHERE TENANT_ID=? OR IS_SHARED = 1) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
||||
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?";
|
||||
return super.getPlatforms(tenantId);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.platform;
|
||||
|
||||
/**
|
||||
* SQL Queries specific to Platform.
|
||||
*/
|
||||
public class SQLQueries {
|
||||
static String queryToGetSupertenantAndOwnPlatforms = "SELECT ID from APPM_PLATFORM where IDENTIFIER "
|
||||
+ "= ? AND (TENANT_ID = ? OR (TENANT_ID = ? AND IS_SHARED = true))";
|
||||
static String queryToGetPlatformId =
|
||||
"SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND "
|
||||
+ "IDENTIFIER=?)";
|
||||
static String queryToGetPlatform =
|
||||
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER, PLATFORM.FILE_BASED, PLATFORM.ID, PLATFORM.NAME, PLATFORM"
|
||||
+ ".DESCRIPTION, PLATFORM.ICON_NAME, PLATFORM.IS_SHARED, PLATFORM.IS_DEFAULT_TENANT_MAPPING FROM "
|
||||
+ "(SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER= ? AND (TENANT_ID=? OR IS_SHARED = TRUE)) "
|
||||
+ "PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID "
|
||||
+ "AND MAPPING.TENANT_ID = ?";
|
||||
static String queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM "
|
||||
+ "WHERE TENANT_ID=? OR IS_SHARED = TRUE ) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
||||
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?";
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.deployer;
|
||||
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Platform represents an Application Platform such as Android, IOS, etc.
|
||||
*/
|
||||
@XmlRootElement(name = "Platform")
|
||||
public class Platform {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private boolean shared;
|
||||
private boolean tenantMapping;
|
||||
private List<Property> properties;
|
||||
|
||||
@XmlAttribute(name = "id")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Property")
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setProperties(List<Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "icon")
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "isShared")
|
||||
public boolean isShared() {
|
||||
return shared;
|
||||
}
|
||||
|
||||
public void setShared(boolean shared) {
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "tenantMapping")
|
||||
public boolean isTenantMapping() {
|
||||
return tenantMapping;
|
||||
}
|
||||
|
||||
public void setTenantMapping(boolean tenantMapping) {
|
||||
this.tenantMapping = tenantMapping;
|
||||
}
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.deployer;
|
||||
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.deployment.AbstractDeployer;
|
||||
import org.apache.axis2.deployment.DeploymentException;
|
||||
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
* PlatformDeployer is responsible for deploying platforms that are added in the filesystem.
|
||||
* This will deploy the platforms that are added in <IOT_HOME>/repository/deployment/server/platforms directory.
|
||||
*/
|
||||
public class PlatformDeployer extends AbstractDeployer {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PlatformDeployer.class);
|
||||
|
||||
@Override
|
||||
public void init(ConfigurationContext configurationContext) {
|
||||
File deployementDir = new File(
|
||||
MultitenantUtils.getAxis2RepositoryPath(CarbonContext.getThreadLocalCarbonContext().
|
||||
getTenantId()) + Constants.PLATFORMS_DEPLOYMENT_DIR_NAME);
|
||||
if (!deployementDir.exists()) {
|
||||
if (!deployementDir.mkdir()) {
|
||||
log.warn("Unable to create the deployment dir at: " + deployementDir.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
|
||||
File deploymentFile = new File(deploymentFileData.getAbsolutePath());
|
||||
try {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(Platform.class);
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
|
||||
if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) {
|
||||
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
|
||||
PlatformManager platformManager = DataHolder.getInstance().getPlatformManager();
|
||||
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
org.wso2.carbon.device.application.mgt.common.Platform existingPlatform = platformManager
|
||||
.getPlatform(tenantID, platform.getIdentifier());
|
||||
if (existingPlatform != null && existingPlatform.isFileBased()) {
|
||||
platformManager.update(tenantID, platformConf.getId(), platform);
|
||||
log.info("Platform configuration : " + deploymentFile.getName() + " updated successfully");
|
||||
} else {
|
||||
platformManager.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
|
||||
log.info("Platform configuration : " + deploymentFile.getName() + " deployed successfully");
|
||||
}
|
||||
} else {
|
||||
log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath()
|
||||
+ "!. Platform config file name - " + deploymentFile.getName()
|
||||
+ " should match with the 'id' provided within the platform configuration!");
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
log.error("Platform configuration file - " + deploymentFile.getAbsolutePath() + " is invalid!", e);
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy(String fileName) throws DeploymentException {
|
||||
String platformId = getPlatformID(fileName);
|
||||
try {
|
||||
DataHolder.getInstance().getPlatformManager()
|
||||
.unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true);
|
||||
log.info("Platform configuration : " + fileName + " un-deployed successfully");
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error occurred while un-deploying the platform - " + fileName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPlatformID(String deploymentFileName) {
|
||||
if (deploymentFileName.contains(Constants.PLATFORM_DEPLOYMENT_EXT)) {
|
||||
return deploymentFileName.substring(0, deploymentFileName.length() -
|
||||
Constants.PLATFORM_DEPLOYMENT_EXT.length());
|
||||
}
|
||||
return deploymentFileName;
|
||||
}
|
||||
|
||||
private org.wso2.carbon.device.application.mgt.common.Platform convert(Platform platformConfig) {
|
||||
org.wso2.carbon.device.application.mgt.common.Platform platform =
|
||||
new org.wso2.carbon.device.application.mgt.common.Platform();
|
||||
platform.setIdentifier(platformConfig.getId());
|
||||
platform.setName(platformConfig.getName());
|
||||
platform.setDescription(platformConfig.getDescription());
|
||||
platform.setIconName(platformConfig.getIcon());
|
||||
platform.setFileBased(true);
|
||||
platform.setShared(platformConfig.isShared());
|
||||
platform.setDefaultTenantMapping(platformConfig.isTenantMapping());
|
||||
platform.setEnabled(false);
|
||||
List<org.wso2.carbon.device.application.mgt.common.Platform.Property> properties = new ArrayList<>();
|
||||
|
||||
if (platformConfig.getProperties() != null) {
|
||||
for (Property propertyConfig : platformConfig.getProperties()) {
|
||||
org.wso2.carbon.device.application.mgt.common.Platform.Property property =
|
||||
new org.wso2.carbon.device.application.mgt.common.Platform.Property();
|
||||
property.setName(propertyConfig.getName());
|
||||
property.setDefaultValue(propertyConfig.getDefaultValue());
|
||||
property.setOptional(propertyConfig.isOptional());
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
platform.setProperties(properties);
|
||||
return platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectory(String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtension(String s) {
|
||||
}
|
||||
}
|
6
components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/DAOException.java → components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/LifeCycleManagementDAOException.java
6
components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/DAOException.java → components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/LifeCycleManagementDAOException.java
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.exception;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
|
||||
/**
|
||||
* Exception that will be thrown when there is a issue during Platform level DAO operations.
|
||||
*/
|
||||
public class PlatformManagementDAOException extends PlatformManagementException {
|
||||
|
||||
public PlatformManagementDAOException(String message, Throwable ex) {
|
||||
super(message, ex);
|
||||
}
|
||||
|
||||
public PlatformManagementDAOException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Category;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationCategoryManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is the default implementation for the CategoryManager.
|
||||
*
|
||||
*/
|
||||
public class CategoryManagerImpl implements CategoryManager {
|
||||
|
||||
@Override
|
||||
public Category createCategory(Category category) throws ApplicationManagementException {
|
||||
if (category == null) {
|
||||
throw new ApplicationCategoryManagementException("Category is null. Cannot create a category.");
|
||||
}
|
||||
if (category.getName() == null) {
|
||||
throw new ApplicationCategoryManagementException(
|
||||
"Application category name cannot be null. Application category creation failed.");
|
||||
}
|
||||
if (getCategory(category.getName()) != null) {
|
||||
throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName()
|
||||
+ "exists already. Please select a different name");
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Category createdCategory = DAOFactory.getCategoryDAO().addCategory(category);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return createdCategory;
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Category> getCategories() throws ApplicationManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return DAOFactory.getCategoryDAO().getCategories();
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getCategory(String name) throws ApplicationManagementException {
|
||||
if (name == null || name.isEmpty()) {
|
||||
throw new ApplicationCategoryManagementException("Name cannot be empty or null. Cannot get category");
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return DAOFactory.getCategoryDAO().getCategory(name);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCategory(String name) throws ApplicationManagementException {
|
||||
Category category = getCategory(name);
|
||||
if (category == null) {
|
||||
throw new NotFoundException(
|
||||
"Category with the name '" + name + "' not found. Cannot delete the " + "non-existing category");
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExist(name);
|
||||
if (isApplicationExistForCategory) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ApplicationCategoryManagementException(
|
||||
"Cannot delete the the category " + name + ". Applications " + "exists for this category");
|
||||
}
|
||||
DAOFactory.getCategoryDAO().deleteCategory(name);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,561 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import org.wso2.carbon.user.api.Tenant;
|
||||
import org.wso2.carbon.user.api.TenantManager;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implementation of {@link PlatformManager}, which manages the CRUD operations on Application platforms.
|
||||
*/
|
||||
public class PlatformManagerImpl implements PlatformManager {
|
||||
private Map<Integer, Map<String, Platform>> inMemoryStore;
|
||||
private static Log log = LogFactory.getLog(PlatformManagerImpl.class);
|
||||
|
||||
public PlatformManagerImpl() {
|
||||
this.inMemoryStore = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(int tenantId) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
List<Platform> platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId);
|
||||
List<String> platformIdentifiers = new ArrayList<>();
|
||||
for (Platform platform : platforms) {
|
||||
if (!platform.isEnabled() & platform.isDefaultTenantMapping()) {
|
||||
platformIdentifiers.add(platform.getIdentifier());
|
||||
}
|
||||
}
|
||||
DAOFactory.getPlatformDAO().addMapping(tenantId, platformIdentifiers);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Transaction Management Exception while initializing the " + "platforms for the tenant : "
|
||||
+ tenantId, e);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while initializing the " + "platforms for the tenant : " + tenantId,
|
||||
e);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementException {
|
||||
int platformIndex = 0;
|
||||
List<Platform> platforms;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request for getting platforms received for the tenant ID " + tenantId + " at "
|
||||
+ "PlatformManager level");
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while getting the platforms for the tenant : " + tenantId, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms received from DAO layer is " + platforms.size() + " for the tenant "
|
||||
+ tenantId);
|
||||
}
|
||||
for (Platform platform : platforms) {
|
||||
if (platform.isFileBased()) {
|
||||
Map<String, Platform> superTenantPlatforms = this.inMemoryStore
|
||||
.get(MultitenantConstants.SUPER_TENANT_ID);
|
||||
Platform registeredPlatform = superTenantPlatforms.get(platform.getIdentifier());
|
||||
if (registeredPlatform != null) {
|
||||
platforms.set(platformIndex, new Platform(registeredPlatform));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Name - " + platform.getName() + ", IsRegistered - " + true);
|
||||
}
|
||||
} else {
|
||||
platforms.remove(platformIndex);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Name - " + platform.getName() + ", IsRegistered - " + false);
|
||||
}
|
||||
}
|
||||
}
|
||||
platformIndex++;
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of effective platforms for the tenant " + tenantId + " : " + platforms.size());
|
||||
}
|
||||
return platforms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementException {
|
||||
Platform platform = getPlatformFromInMemory(tenantId, identifier);
|
||||
if (platform == null) {
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
platform = DAOFactory.getPlatformDAO().getPlatform(tenantId, identifier);
|
||||
if (platform != null) {
|
||||
return platform;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to get the " + "platform with the id :" + identifier
|
||||
+ " for the tenant : " + tenantId, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
} else {
|
||||
return new Platform(platform);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Platform getPlatformFromInMemory(int tenantId, String identifier) {
|
||||
Map<String, Platform> platformMap = this.inMemoryStore.get(tenantId);
|
||||
if (platformMap != null) {
|
||||
Platform platform = platformMap.get(identifier);
|
||||
if (platform != null) {
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
||||
platformMap = this.inMemoryStore.get(MultitenantConstants.SUPER_TENANT_ID);
|
||||
if (platformMap != null) {
|
||||
Platform platform = platformMap.get(identifier);
|
||||
if (platform != null && platform.isShared()) {
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void register(int tenantId, Platform platform) throws PlatformManagementException {
|
||||
validateBeforeRegister(tenantId, platform);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
int platformId = DAOFactory.getPlatformDAO().register(tenantId, platform);
|
||||
if (platform.isFileBased()) {
|
||||
platform.setId(platformId);
|
||||
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId);
|
||||
if (tenantPlatforms == null) {
|
||||
tenantPlatforms = new HashMap<>();
|
||||
this.inMemoryStore.put(tenantId, tenantPlatforms);
|
||||
}
|
||||
if (tenantPlatforms.get(platform.getIdentifier()) == null) {
|
||||
tenantPlatforms.put(platform.getIdentifier(), platform);
|
||||
} else {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementException(
|
||||
"Platform - " + platform.getIdentifier() + " is already registered!");
|
||||
}
|
||||
}
|
||||
if (platform.isDefaultTenantMapping()) {
|
||||
try {
|
||||
if (platform.isShared()) {
|
||||
sharePlatformWithOtherTenants(platform.getIdentifier());
|
||||
}
|
||||
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
|
||||
} catch (UserStoreException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
|
||||
e);
|
||||
}
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Transaction Management Exception while trying to register a " + "platform with id " + platform
|
||||
.getIdentifier() + " for tenant " + tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to register a " + "platform with id " + platform
|
||||
.getIdentifier() + " for tenant " + tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
||||
PlatformManagementException {
|
||||
Platform oldPlatform = validateBeforeUpdate(tenantId, oldPlatformIdentifier, platform);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (platform.isFileBased()) {
|
||||
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId);
|
||||
// File based configurations will be updated in the server start-up as well.So in that case, cache,
|
||||
// will be empty.
|
||||
if (tenantPlatforms != null) {
|
||||
if (tenantPlatforms.get(oldPlatformIdentifier) == null) {
|
||||
throw new PlatformManagementException(
|
||||
"Cannot update platform with identifier " + oldPlatformIdentifier + " as it is not "
|
||||
+ " existing already for the tenant " + tenantId);
|
||||
}
|
||||
} else {
|
||||
tenantPlatforms = new HashMap<>();
|
||||
this.inMemoryStore.put(tenantId, tenantPlatforms);
|
||||
}
|
||||
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
|
||||
platform.setId(oldPlatform.getId());
|
||||
tenantPlatforms.put(platform.getIdentifier(), platform);
|
||||
} else {
|
||||
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
|
||||
}
|
||||
|
||||
try {
|
||||
if (platform.isShared() && !oldPlatform.isShared()) {
|
||||
sharePlatformWithOtherTenants(platform.getIdentifier());
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
|
||||
e);
|
||||
}
|
||||
if (!platform.isShared() && oldPlatform.isShared()) {
|
||||
DAOFactory.getPlatformDAO().removeMappingTenants(platform.getIdentifier());
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Transaction Management Exception while trying to update " + "platform : " + oldPlatformIdentifier
|
||||
+ " of tenant :" + tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to update " + "platform : " + oldPlatformIdentifier
|
||||
+ " of tenant :" + tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(int tenantId, String identifier, boolean isFileBased) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
DAOFactory.getPlatformDAO().unregister(tenantId, identifier, isFileBased);
|
||||
|
||||
if (isFileBased) {
|
||||
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId);
|
||||
if (tenantPlatforms != null) {
|
||||
tenantPlatforms.remove(identifier);
|
||||
}
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Transaction Management Exception while trying to un-register " + "the platform with identifier : "
|
||||
+ identifier + " tenant :" + tenantId, e);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to un-register " + "the platform with identifier : "
|
||||
+ identifier + " tenant :" + tenantId, e);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
DAOFactory.getPlatformDAO().addMapping(tenantId, platformIdentifiers);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (DBConnectionException | TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to add tenant " + "mapping for tenant ID : "
|
||||
+ tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException {
|
||||
List<String> identifiers = new ArrayList<>();
|
||||
identifiers.add(platformIdentifier);
|
||||
addMapping(tenantId, identifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
DAOFactory.getPlatformDAO().removeMapping(tenantId, platformIdentifier);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (DBConnectionException | TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException(
|
||||
"Database Connection Exception while trying to remove tenant mapping for tenant ID : " + tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlatformStatus(int tenantId, String platformIdentifier, String status)
|
||||
throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Platform platform = DAOFactory.getPlatformDAO().getPlatform(tenantId, platformIdentifier);
|
||||
|
||||
if (platform == null) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
throw new PlatformManagementException("Platform with identifier : " + platformIdentifier + " does not"
|
||||
+ " exist for the tenant with id " + tenantId);
|
||||
} else {
|
||||
boolean isEnabledNewStatus = status.equalsIgnoreCase("ENABLED");
|
||||
|
||||
// If the platform is already in the same status. No need to enable the platform again
|
||||
if (isEnabledNewStatus == platform.isEnabled()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform with identifier : " + platformIdentifier + " is already in " +
|
||||
(isEnabledNewStatus ? "Enabled" : "Disabled") + " status. No need to update.");
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return;
|
||||
} else {
|
||||
if (isEnabledNewStatus) {
|
||||
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
|
||||
} else {
|
||||
DAOFactory.getPlatformDAO().removeMapping(tenantId, platform.getIdentifier());
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform with identifier : " + platformIdentifier + " successfully " +
|
||||
(isEnabledNewStatus ? "Enabled" : "Disabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException | DBConnectionException ex) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException("Database exception while trying to update the status of platform "
|
||||
+ "with identifier '" + platformIdentifier + "' for the tenant" + tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlatforms(int tenantId) throws PlatformManagementException {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
DAOFactory.getPlatformDAO().removePlatforms(tenantId);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (TransactionManagementException | DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new PlatformManagementDAOException("Database exception while trying to remove all the platforms for"
|
||||
+ " the tenant " + tenantId);
|
||||
} catch (PlatformManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
* @throws UserStoreException User Store Exception
|
||||
* @throws PlatformManagementDAOException Platform Management DAO Exception
|
||||
*/
|
||||
private void sharePlatformWithOtherTenants(String platformIdentifier)
|
||||
throws UserStoreException, PlatformManagementDAOException {
|
||||
TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager();
|
||||
Tenant[] tenants = tenantManager.getAllTenants();
|
||||
for (Tenant tenant : tenants) {
|
||||
DAOFactory.getPlatformDAO()
|
||||
.addMapping(tenant.getId(), getListOfString(platformIdentifier));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation need to be done before registering the platform
|
||||
*
|
||||
* @param tenantId ID of the tenant which the platform need to registered to
|
||||
* @param platform Platform that need to be registered
|
||||
* @throws PlatformManagementException Platform Management Exception
|
||||
*/
|
||||
private void validateBeforeRegister(int tenantId, Platform platform) throws PlatformManagementException {
|
||||
validatePlatformSharing(tenantId, platform);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
int existingPlatformId = DAOFactory.getPlatformDAO()
|
||||
.getSuperTenantAndOwnPlatforms(platform.getIdentifier(), tenantId);
|
||||
if (existingPlatformId != -1) {
|
||||
throw new PlatformManagementException(
|
||||
"Another platform exists with the identifier " + platform.getIdentifier() + " in the tenant "
|
||||
+ tenantId + " or super-tenant. Please choose a "
|
||||
+ "different identifier for your platform");
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementException(
|
||||
"Error while checking pre-conditions before registering" + " platform identifier '" + platform
|
||||
.getIdentifier() + "' for the tenant :" + tenantId);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validations that need to be done before updating the platform
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param oldPlatformIdentifier Identifier of the old platform
|
||||
* @param platform Updated platform
|
||||
* @return Old platform if all the validation succeeds
|
||||
* @throws PlatformManagementException Platform ManagementException
|
||||
*/
|
||||
private Platform validateBeforeUpdate(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
||||
PlatformManagementException {
|
||||
validatePlatformSharing(tenantId, platform);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
Platform oldPlatform = DAOFactory.getPlatformDAO().getTenantOwnedPlatform(tenantId, oldPlatformIdentifier);
|
||||
if (oldPlatform == null) {
|
||||
throw new PlatformManagementException(
|
||||
"Cannot update platform. Platform with identifier : " + oldPlatformIdentifier
|
||||
+ " does not exist for the tenant : " + tenantId);
|
||||
}
|
||||
if (platform.getIdentifier() != null && !platform.getIdentifier().equals(oldPlatformIdentifier)) {
|
||||
int existingPlatformID = DAOFactory.getPlatformDAO()
|
||||
.getSuperTenantAndOwnPlatforms(platform.getIdentifier(), tenantId);
|
||||
if (existingPlatformID == -1) {
|
||||
throw new PlatformManagementException(
|
||||
"Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '"
|
||||
+ platform.getIdentifier() + "'. Another platform exists "
|
||||
+ "already with the identifier '" + platform.getIdentifier() + "' for the tenant : "
|
||||
+ tenantId + " or in super-tenant");
|
||||
}
|
||||
}
|
||||
return oldPlatform;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementException(
|
||||
"Database error while validating the platform update with the " + "platform identifier: "
|
||||
+ oldPlatformIdentifier + " for the tenant :" + tenantId);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To validate whether this platform can be shared or not before registering and updating the platform
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param platform Platform to be validated for sharing
|
||||
*/
|
||||
private void validatePlatformSharing(int tenantId, Platform platform) throws PlatformManagementException {
|
||||
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
||||
throw new PlatformManagementException(
|
||||
"Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
|
||||
+ " cannot be shared by the tenant domain - " + tenantId);
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
if (platform.isShared()) {
|
||||
int sharedPlatform = DAOFactory.getPlatformDAO().getMultiTenantPlatforms(platform.getIdentifier());
|
||||
if (sharedPlatform != -1) {
|
||||
throw new PlatformManagementException(
|
||||
"Platform '" + platform.getIdentifier() + "' cannot be shared as some other tenants have "
|
||||
+ "platforms with the same identifier.");
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementException(
|
||||
"Error while checking platform sharing conditions for " + " platform identifier '" + platform
|
||||
.getIdentifier() + "' for the tenant :" + tenantId);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the list of the given platform Identifier
|
||||
* @param platformIdentifier Identifier of the Platform
|
||||
* @return Platform Identifier as a list
|
||||
*/
|
||||
private List<String> getListOfString(String platformIdentifier) {
|
||||
List<String> identifiers = new ArrayList<>();
|
||||
identifiers.add(platformIdentifier);
|
||||
return identifiers;
|
||||
}
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
||||
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.ResourceManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil.saveFile;
|
||||
|
||||
/**
|
||||
* This is the concrete implementation of {@link PlatformStorageManager}
|
||||
*/
|
||||
public class PlatformStorageManagerImpl implements PlatformStorageManager {
|
||||
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
|
||||
private String storagePath;
|
||||
|
||||
/**
|
||||
* This creates a new instance of PlatformStorageManager.
|
||||
* @param storagePath Storage path to store the artifacts related with platform.
|
||||
*/
|
||||
public PlatformStorageManagerImpl(String storagePath) {
|
||||
this.storagePath = storagePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadIcon(String platformIdentifier, InputStream iconFileStream) throws ResourceManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Platform platform = validatePlatform(tenantId, platformIdentifier);
|
||||
|
||||
if (platform.isFileBased()) {
|
||||
throw new ApplicationStorageManagementException("Icons for the file based platforms need to be added "
|
||||
+ "directly to the deployment location inside icon folder");
|
||||
}
|
||||
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
||||
throw new PlatformStorageManagementException("Platform " + platformIdentifier
|
||||
+ " is a shared platform from super-tenant. Only the super-tenant users can modify it");
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Artifact Directory Path for saving the artifacts related with application " + platformIdentifier
|
||||
+ " is " + storagePath);
|
||||
}
|
||||
StorageManagementUtil.createArtifactDirectory(storagePath);
|
||||
if (iconFileStream != null) {
|
||||
try {
|
||||
saveFile(iconFileStream, storagePath + File.separator + platform.getId());
|
||||
} catch (IOException e) {
|
||||
throw new ApplicationStorageManagementException(
|
||||
"IO Exception while saving the icon file in the server for the platform " + platformIdentifier,
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageArtifact getIcon(String platformIdentifier) throws PlatformStorageManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Platform platform = validatePlatform(tenantId, platformIdentifier);
|
||||
String imageArtifactPath = storagePath + platform.getId();
|
||||
File imageFile = null;
|
||||
|
||||
if (platform.isFileBased()) {
|
||||
imageFile = new File(MultitenantUtils.getAxis2RepositoryPath(CarbonContext.getThreadLocalCarbonContext().
|
||||
getTenantId()) + Constants.PLATFORMS_DEPLOYMENT_DIR_NAME + File.separator
|
||||
+ Constants.IMAGE_ARTIFACTS[0] + File.separator + platformIdentifier);
|
||||
} else {
|
||||
imageFile = new File(imageArtifactPath);
|
||||
}
|
||||
|
||||
if (!imageFile.exists()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new PlatformStorageManagementException(
|
||||
"File not found exception while trying to get the icon for the " + "platform "
|
||||
+ platformIdentifier, e);
|
||||
} catch (IOException e) {
|
||||
throw new PlatformStorageManagementException(
|
||||
"IO Exception while trying to detect the file type of the platform icon of "
|
||||
+ platformIdentifier, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIcon(String platformIdentifier) throws PlatformStorageManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Platform platform = validatePlatform(tenantId, platformIdentifier);
|
||||
String imageArtifactPath = storagePath + platform.getId();
|
||||
|
||||
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
||||
throw new PlatformStorageManagementException("Platform " + platformIdentifier + " is a shared platform "
|
||||
+ "from super-tenant. Only the super-tenant users can modify it");
|
||||
}
|
||||
if (platform.isFileBased()) {
|
||||
throw new PlatformStorageManagementException("Platform " + platformIdentifier + " is a file based one. "
|
||||
+ "Please remove the relevant icon file directly from file system.");
|
||||
}
|
||||
|
||||
File imageFile = new File(imageArtifactPath);
|
||||
if (imageFile.exists()) {
|
||||
imageFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To validate the platform, whether the given identifier has a valid platform.
|
||||
*
|
||||
* @param tenantId ID of the tenant
|
||||
* @param identifier Identifier of the platform
|
||||
* @return Platform related with the particular identifier.
|
||||
*/
|
||||
private Platform validatePlatform(int tenantId, String identifier) throws PlatformStorageManagementException {
|
||||
Platform platform;
|
||||
try {
|
||||
PlatformManager platformManager = DataHolder.getInstance().getPlatformManager();
|
||||
platform = platformManager.getPlatform(tenantId, identifier);
|
||||
} catch (PlatformManagementException e) {
|
||||
throw new PlatformStorageManagementException(
|
||||
"Platform Management Exception while getting the platform " + "related with the identifier "
|
||||
+ identifier);
|
||||
}
|
||||
|
||||
if (platform == null) {
|
||||
throw new PlatformStorageManagementException("Platform does not exist with the identifier " + identifier);
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.internal;
|
||||
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
|
||||
|
||||
/**
|
||||
* PlatformManagementAxis2ConfigurationObserverImpl is responsible for adding relevant platform mapping of shared
|
||||
* platforms during the tenant creation time.
|
||||
*/
|
||||
public class PlatformManagementAxis2ConfigurationObserverImpl extends AbstractAxis2ConfigurationContextObserver {
|
||||
private static Log log = LogFactory.getLog(PlatformManagementAxis2ConfigurationObserverImpl.class);
|
||||
|
||||
/**
|
||||
* Whenever a new tenant creation happens, shared platforms need to be added for the relevant tenant.
|
||||
* @param tenantId Id of the tenant that is being created
|
||||
*/
|
||||
@Override
|
||||
public void creatingConfigurationContext(int tenantId) {
|
||||
try {
|
||||
DataHolder.getInstance().getPlatformManager().initialize(tenantId);
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while trying add platforms to the newly created tenant " + tenantId, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whenever terminating a tenant,the platforms added by the tenant need to be removed.
|
||||
* @param configContext Configuration context.
|
||||
*/
|
||||
@Override
|
||||
public void terminatingConfigurationContext(ConfigurationContext configContext) {
|
||||
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
int tenantId = carbonContext.getTenantId();
|
||||
try {
|
||||
DataHolder.getInstance().getPlatformManager().removePlatforms(tenantId);
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while removing shared platforms while removing the tenant: " + tenantId, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/",
|
||||
"layout": "cdmf.layout.default"
|
||||
"layout": "cdmf.layout.default",
|
||||
"isAnonymous" : true
|
||||
}
|
Loading…
Reference in new issue