forked from community/device-mgt-core
commit
ec4e8255a2
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel(value = "TagInfo", description = "Tag details including parameters associated with tags " +
|
||||
"wrapped here.")
|
||||
public class TagInfo {
|
||||
|
||||
@ApiModelProperty(name = "name", value = "The name of the tag.", required = true)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "description", value = "Describes the behavior of the tag.",
|
||||
required = false)
|
||||
private String description;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "TagInfoList")
|
||||
public class TagInfoList extends BasePaginatedResult {
|
||||
|
||||
private List<String> tags;
|
||||
|
||||
@ApiModelProperty(value = "Returns the list of tags that match the offset and limit parameter values "
|
||||
+ "that were specified.")
|
||||
@JsonProperty("tags")
|
||||
public List<String> getList() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setList(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" tags: [").append(tags).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "TagMappingInfo", description = "Tag mapping details including parameters associated with " +
|
||||
"device mapping wrapped here.")
|
||||
public class TagMappingInfo {
|
||||
|
||||
@ApiModelProperty(name = "deviceIdentifiers", value = "Defines the device identifiers.", required = true)
|
||||
private List<String> deviceIdentifiers;
|
||||
|
||||
@ApiModelProperty(name = "deviceType", value = "Defines the device type.", required = true)
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty(name = "tags", value = "Defines the tags.", required = true)
|
||||
private List<String> tags;
|
||||
|
||||
public List<String> getDeviceIdentifiers() {
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifiers(List<String> deviceIdentifiers) {
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "TagMappingInfoList")
|
||||
public class TagMappingInfoList extends BasePaginatedResult {
|
||||
|
||||
private List<String> tagMappings;
|
||||
|
||||
@ApiModelProperty(value = "Returns the list of tag mappings that match the offset and "
|
||||
+ "limit parameter values that were specified.")
|
||||
@JsonProperty("tagMappings")
|
||||
public List<String> getList() {
|
||||
return tagMappings;
|
||||
}
|
||||
|
||||
public void setList(List<String> tagMappings) {
|
||||
this.tagMappings = tagMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" tagMappings: [").append(tagMappings).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.TagInfo;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.TagInfoList;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.TagMappingInfo;
|
||||
import io.swagger.annotations.*;
|
||||
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
|
||||
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "TagManagement"),
|
||||
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/tags"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "device_management")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Getting the List of Tags",
|
||||
description = "Getting the List of Tags",
|
||||
key = "tm:tags:view",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/view"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Adding a new tag",
|
||||
description = "Adding a new tag",
|
||||
key = "tm:tags:create",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/create"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Updating a tag",
|
||||
description = "Updating a tag",
|
||||
key = "tm:tags:update",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/update"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Delete a tag",
|
||||
description = "Delete a tag",
|
||||
key = "tm:tags:delete",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/delete"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Adding a device tag mapping",
|
||||
description = "Adding a device-tag mapping",
|
||||
key = "tm:tags:mapping:create",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/mapping/create"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Deleting a device tag mapping",
|
||||
description = "Deleting a device-tag mapping",
|
||||
key = "tm:tags:mapping:delete",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/mapping/delete"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Getting the list of device tag mappings",
|
||||
description = "Getting the list of device-tag mappings",
|
||||
key = "tm:tags:mapping:view",
|
||||
roles = {"Internal/devicemgt-user"},
|
||||
permissions = {"/device-mgt/tags/mapping/view"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Path("/tags")
|
||||
@Api(value = "Tag Management", description = "Tag management related operations can be found here.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface TagManagementService {
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting the List of Tags",
|
||||
notes = "This endpoint is used to retrieve all tags",
|
||||
tags = "Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched the list of tags.",
|
||||
response = TagInfoList.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching list of roles.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getTags();
|
||||
|
||||
@POST
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Adding a Tag",
|
||||
notes = "This endpoint is used to add new tags",
|
||||
tags = "Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully created the tag.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The URL to the newly added tag."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The Source URL of the document.")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not supported.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while adding a new tag.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response addTag(
|
||||
@ApiParam(
|
||||
name = "tag",
|
||||
value = "The properties required to add a new tag.",
|
||||
required = true) List<TagInfo> tags);
|
||||
|
||||
@PUT
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Updating a Tag",
|
||||
notes = "This endpoint is used to update a specific tag",
|
||||
tags = "Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully updated the tag.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified tag does not exist.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while updating the tag.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response updateTag(
|
||||
@ApiParam(
|
||||
name = "tagId",
|
||||
value = "The ID of the tag to be updated.",
|
||||
required = false) @QueryParam("tagId") Integer tagId,
|
||||
@ApiParam(
|
||||
name = "tagName",
|
||||
value = "The name of the tag to be updated.",
|
||||
required = false) @QueryParam("tagName") String tagName,
|
||||
@ApiParam(
|
||||
name = "tagInfo",
|
||||
value = "The properties required to update the tag.",
|
||||
required = true) TagInfo tagInfo);
|
||||
|
||||
@DELETE
|
||||
@Path("/{tagId}")
|
||||
@ApiOperation(
|
||||
httpMethod = "DELETE",
|
||||
value = "Deleting a Tag",
|
||||
notes = "This endpoint is used to delete a specific tag",
|
||||
tags = "Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:delete")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 204,
|
||||
message = "No Content. \n Successfully deleted the tag."),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified tag does not exist.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while deleting the tag.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response deleteTag(
|
||||
@ApiParam(
|
||||
name = "tagId",
|
||||
value = "The ID of the tag to be deleted.",
|
||||
required = true) @PathParam("tagId") int tagId);
|
||||
|
||||
@GET
|
||||
@Path("/{tagId}")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting a Tag by ID",
|
||||
notes = "This endpoint is used to retrieve tag by id",
|
||||
tags = "Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched the tag.",
|
||||
response = Tag.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")}),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified tag does not exist.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while fetching the tag.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getTagById(
|
||||
@ApiParam(
|
||||
name = "tagId",
|
||||
value = "The ID of the tag to be fetched.",
|
||||
required = true) @PathParam("tagId") int tagId);
|
||||
|
||||
@POST
|
||||
@Path("/mapping")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Adding a Device-Tag Mapping",
|
||||
notes = "This endpoint is used to map devices with tags",
|
||||
tags = "Device-Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:mapping:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created. \n Successfully created the device-tag mapping.",
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Location",
|
||||
description = "The URL to the newly added device-tag mapping."),
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while adding the device-tag mapping.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response addDeviceTagMapping(
|
||||
@ApiParam(
|
||||
name = "deviceTagInfo",
|
||||
value = "The properties required to add a new device-tag mapping.",
|
||||
required = true) TagMappingInfo tagMappingInfo);
|
||||
|
||||
@DELETE
|
||||
@Path("/mapping")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "DELETE",
|
||||
value = "Deleting a Device-Tag Mapping",
|
||||
notes = "This endpoint is used to remove tag mappings from devices",
|
||||
tags = "Device-Tag Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "tm:tags:mapping:delete")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 204,
|
||||
message = "No Content. \n Successfully deleted the device-tag mapping."),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Server error occurred while deleting the device-tag mapping.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response deleteDeviceTagMapping(
|
||||
@ApiParam(
|
||||
name = "deviceTagInfo",
|
||||
value = "The properties required to add a new device-tag mapping.",
|
||||
required = true) TagMappingInfo tagMappingInfo);
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.TagInfo;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.TagMappingInfo;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.TagManagementService;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.TagManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.TagNotFoundException;
|
||||
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
|
||||
import io.entgra.device.mgt.core.notification.logger.impl.EntgraRoleMgtLoggerImpl;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/tags")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class TagManagementServiceImpl implements TagManagementService {
|
||||
|
||||
private static final EntgraLogger log = new EntgraRoleMgtLoggerImpl(TagManagementServiceImpl.class);
|
||||
|
||||
@GET
|
||||
@Override
|
||||
public Response getTags() {
|
||||
try {
|
||||
List<Tag> tags = DeviceMgtAPIUtils.getTagManagementService().getAllTags();
|
||||
return Response.status(Response.Status.OK).entity(tags).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while getting tags.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Override
|
||||
public Response addTag(List<TagInfo> tagInfoList) {
|
||||
RequestValidationUtil.validateTagListDetails(tagInfoList);
|
||||
try {
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
for (TagInfo tagInfo : tagInfoList) {
|
||||
Tag tag = new Tag(tagInfo.getName(), tagInfo.getDescription());
|
||||
tags.add(tag);
|
||||
}
|
||||
DeviceMgtAPIUtils.getTagManagementService().addTags(tags);
|
||||
return Response.status(Response.Status.CREATED).entity(tagInfoList).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while adding tags." ;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity
|
||||
(new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Error occurred while adding tags. Please check the request" ;
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug(msg, e);
|
||||
}
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Override
|
||||
public Response updateTag(@QueryParam("tagId") Integer tagId, @QueryParam("tagName") String tagName, TagInfo tagInfo) {
|
||||
RequestValidationUtil.validateTagDetails(tagId, tagName, tagInfo);
|
||||
try {
|
||||
Tag tag;
|
||||
if (tagId != null) {
|
||||
tag = DeviceMgtAPIUtils.getTagManagementService().getTagById(tagId);
|
||||
} else {
|
||||
tag = DeviceMgtAPIUtils.getTagManagementService().getTagByName(tagName);
|
||||
}
|
||||
if (tag == null) {
|
||||
String msg = (tagId != null) ? "Tag with ID " + tagId + " is not found."
|
||||
: "Tag with name " + tagName + " is not found.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage(msg).build()).build();
|
||||
}
|
||||
tag.setName(tagInfo.getName());
|
||||
tag.setDescription(tagInfo.getDescription());
|
||||
DeviceMgtAPIUtils.getTagManagementService().updateTag(tag);
|
||||
return Response.status(Response.Status.OK).entity(tag).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = (tagId != null) ? "Error occurred while updating tag with ID " + tagId + "."
|
||||
: "Error occurred while updating tag with name " + tagName + ".";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (TagNotFoundException e) {
|
||||
String msg = (tagId != null) ? "Tag with ID " + tagId + " is not found."
|
||||
: "Tag with name " + tagName + " is not found.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage(msg).build()).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = (tagId != null) ? "Error occurred while updating tag with ID " + tagId
|
||||
: "Error occurred while updating tag with name " + tagName;
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug(msg, e);
|
||||
}
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{tagId}")
|
||||
@Override
|
||||
public Response deleteTag(@PathParam("tagId") int tagId) {
|
||||
try {
|
||||
DeviceMgtAPIUtils.getTagManagementService().deleteTag(tagId);
|
||||
return Response.status(Response.Status.NO_CONTENT).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while deleting tag with ID " + tagId + ".";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage(msg).build()).build();
|
||||
} catch (TagNotFoundException e) {
|
||||
String msg = "Tag with ID " + tagId + " is not found.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.ErrorResponseBuilder().
|
||||
setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{tagId}")
|
||||
@Override
|
||||
public Response getTagById(@PathParam("tagId") int tagId) {
|
||||
try {
|
||||
Tag tag = DeviceMgtAPIUtils.getTagManagementService().getTagById(tagId);
|
||||
return Response.status(Response.Status.OK).entity(tag).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while getting tag with ID " + tagId + ".";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (TagNotFoundException e) {
|
||||
String msg = "Tag with ID " + tagId + " is not found.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/mapping")
|
||||
public Response addDeviceTagMapping(TagMappingInfo tagMappingInfo) {
|
||||
RequestValidationUtil.validateTagMappingDetails(tagMappingInfo);
|
||||
try {
|
||||
DeviceMgtAPIUtils.getTagManagementService().addDeviceTagMapping(tagMappingInfo.getDeviceIdentifiers(),
|
||||
tagMappingInfo.getDeviceType(), tagMappingInfo.getTags());
|
||||
return Response.status(Response.Status.CREATED).entity(tagMappingInfo).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while adding device-tag mapping.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Error occurred while adding tag mappings.";
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug(msg, e);
|
||||
}
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/mapping")
|
||||
public Response deleteDeviceTagMapping(TagMappingInfo tagMappingInfo) {
|
||||
RequestValidationUtil.validateTagMappingDetails(tagMappingInfo);
|
||||
try {
|
||||
DeviceMgtAPIUtils.getTagManagementService().deleteDeviceTagMapping(tagMappingInfo.getDeviceIdentifiers(),
|
||||
tagMappingInfo.getDeviceType(), tagMappingInfo.getTags());
|
||||
return Response.status(Response.Status.NO_CONTENT).entity(tagMappingInfo).build();
|
||||
} catch (TagManagementException e) {
|
||||
String msg = "Error occurred while deleting tag mappings.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Error occurred while deleting tag mappings.";
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug(msg, e);
|
||||
}
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorResponse.
|
||||
ErrorResponseBuilder().setMessage(e.getMessage()).build()).build();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.tag.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* DTO of DeviceTag object which is used to manage Device Tags.
|
||||
*/
|
||||
|
||||
@ApiModel(value = "DeviceTag", description = "This is used to manage device tags.")
|
||||
public class DeviceTag {
|
||||
|
||||
@ApiModelProperty(name = "enrolmentId", value = "Defines the device id.", required = true)
|
||||
private int enrolmentId;
|
||||
|
||||
@ApiModelProperty(name = "tagId", value = "Defines the tag id.", required = true)
|
||||
private int tagId;
|
||||
|
||||
public int getEnrolmentId() {
|
||||
return enrolmentId;
|
||||
}
|
||||
|
||||
public void setEnrolmentId(int enrolmentId) {
|
||||
this.enrolmentId = enrolmentId;
|
||||
}
|
||||
|
||||
public int getTagId() {
|
||||
return tagId;
|
||||
}
|
||||
|
||||
public void setTagId(int tagId) {
|
||||
this.tagId = tagId;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.tag.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* DTO of Tag object which is used to manage Tags in devices.
|
||||
*/
|
||||
|
||||
@ApiModel(value = "Tag", description = "This is used to manage tags in devices.")
|
||||
public class Tag {
|
||||
|
||||
@ApiModelProperty(name = "id", value = "Defines the tag ID.", required = false)
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(name = "name", value = "Defines the tag name.", required = true)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "description", value = "Defines the tag description.", required = false)
|
||||
private String description;
|
||||
|
||||
public Tag(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Tag() {}
|
||||
|
||||
public Tag(int id, String name, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tag {" +
|
||||
" id= " + id +
|
||||
", name= '" + name + '\'' +
|
||||
", description= '" + description + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.tag.mgt;
|
||||
|
||||
/**
|
||||
* Custom exception class to be used in TagManagement related functionalities.
|
||||
*/
|
||||
public class TagManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8933146283800122660L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public TagManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TagManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public TagManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TagManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TagManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.tag.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO of TagMapping object which is used to manage Device Tags.
|
||||
*/
|
||||
|
||||
@ApiModel(value = "TagMappingDTO", description = "This is used to manage device tags.")
|
||||
public class TagMappingDTO {
|
||||
|
||||
@ApiModelProperty(name = "deviceIdentifiers", value = "Defines the device identifiers.", required = true)
|
||||
private List<String> deviceIdentifiers;
|
||||
|
||||
@ApiModelProperty(name = "deviceType", value = "Defines the device type.", required = true)
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty(name = "tags", value = "Defines the tag.", required = true)
|
||||
private List<String> tags;
|
||||
|
||||
public TagMappingDTO() {}
|
||||
|
||||
public TagMappingDTO(List<String> deviceIdentifiers, String deviceType, List<String> tags) {
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
this.deviceType = deviceType;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public List<String> getDeviceIdentifiers() {
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifiers(List<String> deviceIdentifiers) {
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.tag.mgt;
|
||||
|
||||
/**
|
||||
* Custom exception class to be used in TagManagement related functionalities.
|
||||
*/
|
||||
public class TagNotFoundException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8933146283800122660L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public TagNotFoundException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TagNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public TagNotFoundException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public TagNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TagNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.dao;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.DeviceTag;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface represents the key operations associated with persisting tag related information.
|
||||
*/
|
||||
public interface TagDAO {
|
||||
|
||||
/**
|
||||
* Add a new tag.
|
||||
*
|
||||
* @param tags to be added.
|
||||
* @param tenantId of the tag.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
void addTags(List<Tag> tags, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update an existing tag.
|
||||
*
|
||||
* @param tag to be updated.
|
||||
* @param tenantId of the tag.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
void updateTag(Tag tag, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete an existing tag.
|
||||
*
|
||||
* @param tagId of the tag.
|
||||
* @param tenantId of the tag.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
void deleteTag(int tagId, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get a tag by id.
|
||||
*
|
||||
* @param tagId of the tag.
|
||||
* @param tenantId of the tag.
|
||||
* @return Tag object.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
Tag getTagById(int tagId, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Method to retrieve a tag by its name.
|
||||
*
|
||||
* @param tagName - Name of the tag to be retrieved.
|
||||
* @param tenantId - Tenant ID.
|
||||
* @return Tag object retrieved from the database.
|
||||
* @throws TagManagementDAOException if something goes wrong while retrieving the Tag.
|
||||
*/
|
||||
Tag getTagByName(String tagName, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get all tags for a tenant.
|
||||
*
|
||||
* @param tenantId of the tag.
|
||||
* @return List of all tags.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
List<Tag> getTags(int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Add a device tag mapping.
|
||||
*
|
||||
* @param deviceIdentifiers of the mapping.
|
||||
* @param deviceType of the mapping.
|
||||
* @param tagNames of the mapping.
|
||||
* @param tenantId of the mapping.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
void addDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tagNames, int tenantId)
|
||||
throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a device tag mapping.
|
||||
*
|
||||
* @param deviceIdentifiers of the mapping.
|
||||
* @param deviceType of the mapping.
|
||||
* @param tagNames of the mapping.
|
||||
* @param tenantId of the mapping.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
void deleteDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tagNames, int tenantId)
|
||||
throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get all device tags for a device.
|
||||
*
|
||||
* @param deviceId of the device.
|
||||
* @param tenantId of the mapping.
|
||||
* @return List of device tags.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
List<DeviceTag> getTagsForDevice(int deviceId, int tenantId) throws TagManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get all devices for a tag.
|
||||
*
|
||||
* @param tagId of the tag.
|
||||
* @param tenantId of the mapping.
|
||||
* @return List of device tags.
|
||||
* @throws TagManagementDAOException
|
||||
*/
|
||||
List<DeviceTag> getDevicesForTag(int tagId, int tenantId) throws TagManagementDAOException;
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.dao;
|
||||
|
||||
/**
|
||||
* Custom exception class for tag management data access related exceptions.
|
||||
*/
|
||||
public class TagManagementDAOException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 2021891706072918864L;
|
||||
private String message;
|
||||
private boolean uniqueConstraintViolation;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and nested exception.
|
||||
*
|
||||
* @param message error message
|
||||
* @param nestedException exception
|
||||
*/
|
||||
public TagManagementDAOException(String message, Exception nestedException) {
|
||||
super(message, nestedException);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public TagManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public TagManagementDAOException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified cause.
|
||||
*
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public TagManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TagManagementDAOException(String message, Throwable cause, boolean uniqueConstraintViolation) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
this.uniqueConstraintViolation = uniqueConstraintViolation;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.message = errorMessage;
|
||||
}
|
||||
|
||||
public boolean isUniqueConstraintViolation() {
|
||||
return uniqueConstraintViolation;
|
||||
}
|
||||
}
|
@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.dao.impl;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.DeviceTag;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.dao.*;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static io.entgra.device.mgt.core.device.mgt.core.dao.util.TagManagementDAOUtil.loadDeviceTagMapping;
|
||||
import static io.entgra.device.mgt.core.device.mgt.core.dao.util.TagManagementDAOUtil.loadTag;
|
||||
import static io.entgra.device.mgt.core.device.mgt.core.dao.util.TagManagementDAOUtil.cleanupResources;
|
||||
|
||||
public class TagDAOImpl implements TagDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TagDAOImpl.class);
|
||||
|
||||
protected Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTags(List<Tag> tags, int tenantId) throws TagManagementDAOException {
|
||||
String query = "INSERT INTO DM_TAG (NAME, DESCRIPTION, TENANT_ID) " +
|
||||
"SELECT ?, ?, ? " +
|
||||
"WHERE NOT EXISTS ( " +
|
||||
" SELECT 1 FROM DM_TAG " +
|
||||
" WHERE NAME = ? AND TENANT_ID = ? " +
|
||||
")";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
for (Tag tag : tags) {
|
||||
preparedStatement.setString(1, tag.getName());
|
||||
preparedStatement.setString(2, tag.getDescription());
|
||||
preparedStatement.setInt(3, tenantId);
|
||||
preparedStatement.setString(4, tag.getName());
|
||||
preparedStatement.setInt(5, tenantId);
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
int[] updateCounts = preparedStatement.executeBatch();
|
||||
for (int count : updateCounts) {
|
||||
if (count == PreparedStatement.EXECUTE_FAILED) {
|
||||
String msg = "Error occurred while adding tags, adding some tags failed.";
|
||||
log.error(msg);
|
||||
throw new TagManagementDAOException(msg);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding tags.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTag(Tag tag, int tenantId) throws TagManagementDAOException {
|
||||
String query = "UPDATE DM_TAG SET NAME = ?, DESCRIPTION = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setString(1, tag.getName());
|
||||
preparedStatement.setString(2, tag.getDescription());
|
||||
preparedStatement.setInt(3, tag.getId());
|
||||
preparedStatement.setInt(4, tenantId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating tag.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTag(int tagId, int tenantId) throws TagManagementDAOException {
|
||||
String query = "DELETE FROM DM_TAG WHERE ID = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, tagId);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting tag.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getTagById(int tagId, int tenantId) throws TagManagementDAOException {
|
||||
String query = "SELECT * FROM DM_TAG WHERE ID = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
Tag tag = null;
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, tagId);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
tag = loadTag(resultSet);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while getting a specific tag." + tagId;
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getTagByName(String tagName, int tenantId) throws TagManagementDAOException {
|
||||
String query = "SELECT * FROM DM_TAG WHERE NAME = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
Tag tag = null;
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setString(1, tagName);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
tag = loadTag(resultSet);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving tag with name: " + tagName;
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Tag> getTags(int tenantId) throws TagManagementDAOException {
|
||||
String query = "SELECT * FROM DM_TAG WHERE TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, tenantId);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
Tag tag = loadTag(resultSet);
|
||||
tags.add(tag);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving tags";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tagNames, int tenantId) throws TagManagementDAOException {
|
||||
String deviceIdentifiersPlaceholders = String.join(", ", Collections.nCopies(deviceIdentifiers.size(), "?"));
|
||||
String tagNamesPlaceholders = String.join(", ", Collections.nCopies(tagNames.size(), "?"));
|
||||
|
||||
String query = String.format(
|
||||
"INSERT INTO DM_DEVICE_TAG_MAPPING (ENROLMENT_ID, TAG_ID, TENANT_ID) " +
|
||||
"SELECT e.ID, t.ID, ? " +
|
||||
"FROM DM_ENROLMENT e " +
|
||||
"JOIN DM_DEVICE d ON d.ID = e.DEVICE_ID " +
|
||||
"JOIN DM_TAG t ON t.NAME IN (%s) " +
|
||||
"WHERE d.DEVICE_IDENTIFICATION IN (%s) " +
|
||||
"AND e.DEVICE_TYPE = ? " +
|
||||
"AND e.STATUS != 'REMOVED' " +
|
||||
"AND e.TENANT_ID = ? " +
|
||||
"AND t.TENANT_ID = ? " +
|
||||
"AND NOT EXISTS ( " +
|
||||
" SELECT 1 " +
|
||||
" FROM DM_DEVICE_TAG_MAPPING m " +
|
||||
" WHERE m.ENROLMENT_ID = e.ID " +
|
||||
" AND m.TAG_ID = t.ID " +
|
||||
" AND m.TENANT_ID = ? " +
|
||||
")",
|
||||
tagNamesPlaceholders,
|
||||
deviceIdentifiersPlaceholders
|
||||
);
|
||||
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
int paramIndex = 1;
|
||||
preparedStatement.setInt(paramIndex++, tenantId);
|
||||
for (String tagName : tagNames) {
|
||||
preparedStatement.setString(paramIndex++, tagName);
|
||||
}
|
||||
for (String deviceIdentifier : deviceIdentifiers) {
|
||||
preparedStatement.setString(paramIndex++, deviceIdentifier);
|
||||
}
|
||||
preparedStatement.setString(paramIndex++, deviceType);
|
||||
preparedStatement.setInt(paramIndex++, tenantId);
|
||||
preparedStatement.setInt(paramIndex++, tenantId);
|
||||
preparedStatement.setInt(paramIndex, tenantId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLIntegrityConstraintViolationException e) {
|
||||
String msg = "Tag is already mapped to this device";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e, true);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding device tag mapping";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tagNames, int tenantId) throws TagManagementDAOException {
|
||||
String deviceIdentifiersPlaceholders = String.join(", ", Collections.nCopies(deviceIdentifiers.size(), "?"));
|
||||
String tagNamesPlaceholders = String.join(", ", Collections.nCopies(tagNames.size(), "?"));
|
||||
|
||||
String query = String.format(
|
||||
"DELETE FROM DM_DEVICE_TAG_MAPPING " +
|
||||
"WHERE ENROLMENT_ID IN ( " +
|
||||
" SELECT e.ID " +
|
||||
" FROM DM_ENROLMENT e " +
|
||||
" JOIN DM_DEVICE d ON d.ID = e.DEVICE_ID " +
|
||||
" WHERE d.DEVICE_IDENTIFICATION IN (%s) " +
|
||||
" AND e.DEVICE_TYPE = ? " +
|
||||
" AND e.TENANT_ID = ? " +
|
||||
" AND e.STATUS != 'REMOVED' " +
|
||||
") " +
|
||||
"AND TAG_ID IN ( " +
|
||||
" SELECT t.ID " +
|
||||
" FROM DM_TAG t " +
|
||||
" WHERE t.NAME IN (%s) " +
|
||||
" AND t.TENANT_ID = ? " +
|
||||
")",
|
||||
deviceIdentifiersPlaceholders,
|
||||
tagNamesPlaceholders
|
||||
);
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
int paramIndex = 1;
|
||||
for (String deviceIdentifier : deviceIdentifiers) {
|
||||
preparedStatement.setString(paramIndex++, deviceIdentifier);
|
||||
}
|
||||
preparedStatement.setString(paramIndex++, deviceType);
|
||||
preparedStatement.setInt(paramIndex++, tenantId);
|
||||
for (String tagName : tagNames) {
|
||||
preparedStatement.setString(paramIndex++, tagName);
|
||||
}
|
||||
preparedStatement.setInt(paramIndex, tenantId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting device tag mapping";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceTag> getTagsForDevice(int deviceId, int tenantId) throws TagManagementDAOException {
|
||||
String query = "SELECT * FROM DM_DEVICE_TAG_MAPPING WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceTag> deviceTags = new ArrayList<>();
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, deviceId);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
DeviceTag deviceTag = loadDeviceTagMapping(resultSet);
|
||||
deviceTags.add(deviceTag);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving device tags";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
return deviceTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceTag> getDevicesForTag(int tagId, int tenantId) throws TagManagementDAOException {
|
||||
String query = "SELECT * FROM DM_DEVICE_TAG_MAPPING WHERE TAG_ID = ? AND TENANT_ID = ?";
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<DeviceTag> deviceTags = new ArrayList<>();
|
||||
|
||||
try {
|
||||
connection = getConnection();
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setInt(1, tagId);
|
||||
preparedStatement.setInt(2, tenantId);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
DeviceTag deviceTag = loadDeviceTagMapping(resultSet);
|
||||
deviceTags.add(deviceTag);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving devices for tag";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementDAOException(msg, e);
|
||||
} finally {
|
||||
cleanupResources(preparedStatement, resultSet);
|
||||
}
|
||||
return deviceTags;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.dao.util;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.DeviceTag;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* This class represents utilities required to work with tag management data
|
||||
*/
|
||||
public final class TagManagementDAOUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TagManagementDAOUtil.class);
|
||||
|
||||
/**
|
||||
* Cleanup resources used to transaction
|
||||
*
|
||||
* @param stmt Prepared statement used
|
||||
* @param rs Obtained results set
|
||||
*/
|
||||
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup datasource using name and jndi properties
|
||||
*
|
||||
* @param dataSourceName Name of datasource to lookup
|
||||
* @param jndiProperties Hash table of JNDI Properties
|
||||
* @return datasource looked
|
||||
*/
|
||||
public static DataSource lookupDataSource(String dataSourceName,
|
||||
final Hashtable<Object, Object> jndiProperties) {
|
||||
try {
|
||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||
}
|
||||
final InitialContext context = new InitialContext(jndiProperties);
|
||||
return (DataSource) context.lookup(dataSourceName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tag loadTag(ResultSet resultSet) throws SQLException {
|
||||
Tag tag = new Tag();
|
||||
tag.setId(resultSet.getInt("ID"));
|
||||
tag.setName(resultSet.getString("NAME"));
|
||||
tag.setDescription(resultSet.getString("DESCRIPTION"));
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static DeviceTag loadDeviceTagMapping(ResultSet resultSet) throws SQLException {
|
||||
DeviceTag deviceTag = new DeviceTag();
|
||||
deviceTag.setEnrolmentId(resultSet.getInt("ENROLMENT_ID"));
|
||||
deviceTag.setTagId(resultSet.getInt("TAG_ID"));
|
||||
return deviceTag;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.service;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines the contract of TagManagementService.
|
||||
*/
|
||||
public interface TagManagementProviderService {
|
||||
|
||||
/**
|
||||
* Method to add a tag to the database.
|
||||
*
|
||||
* @param tag - Tag to be added to the database.
|
||||
* @throws TagManagementException if something goes wrong while adding the Tag.
|
||||
*/
|
||||
void addTags(List<Tag> tag) throws TagManagementException, BadRequestException;
|
||||
|
||||
/**
|
||||
* Method to fetch all tags.
|
||||
*
|
||||
* @return List of all Tags.
|
||||
* @throws TagManagementException if something goes wrong while fetching the Tags.
|
||||
*/
|
||||
List<Tag> getAllTags() throws TagManagementException;
|
||||
|
||||
/**
|
||||
* Method to update a tag in the database.
|
||||
*
|
||||
* @param tag - Tag to be updated in the database.
|
||||
* @throws TagManagementException if something goes wrong while updating the Tag.
|
||||
*/
|
||||
void updateTag(Tag tag) throws TagManagementException, TagNotFoundException, BadRequestException;
|
||||
|
||||
/**
|
||||
* Method to delete a tag from the database.
|
||||
*
|
||||
* @param tagId - ID of the tag to be deleted.
|
||||
* @throws TagManagementException if something goes wrong while deleting the Tag.
|
||||
*/
|
||||
void deleteTag(int tagId) throws TagManagementException, TagNotFoundException;
|
||||
|
||||
/**
|
||||
* Method to retrieve a tag by its ID.
|
||||
*
|
||||
* @param tagId - ID of the tag to be retrieved.
|
||||
* @return Tag object retrieved from the database.
|
||||
* @throws TagManagementException if something goes wrong while retrieving the Tag.
|
||||
*/
|
||||
Tag getTagById(int tagId) throws TagManagementException, TagNotFoundException;
|
||||
|
||||
/**
|
||||
* Method to retrieve a tag by its name.
|
||||
*
|
||||
* @param tagName - Name of the tag to be retrieved.
|
||||
* @return Tag object retrieved from the database.
|
||||
* @throws TagManagementException if something goes wrong while retrieving the Tag.
|
||||
* @throws TagNotFoundException if the Tag with the given name is not found.
|
||||
*/
|
||||
Tag getTagByName(String tagName) throws TagManagementException, TagNotFoundException, BadRequestException;
|
||||
|
||||
/**
|
||||
* Method to add a device-tag mapping.
|
||||
*
|
||||
* @param deviceIdentifiers - List of device ids to map.
|
||||
* @param deviceType - Device Type of that specific devices.
|
||||
* @param tags - List of tags you want to attach.
|
||||
* @throws TagManagementException if something goes wrong while adding the device-tag mapping.
|
||||
*/
|
||||
void addDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tags)
|
||||
throws TagManagementException, BadRequestException;
|
||||
|
||||
/**
|
||||
* Method to delete a device-tag mapping.
|
||||
*
|
||||
* @param deviceIdentifiers - List of device ids to map.
|
||||
* @param deviceType - Device Type of that specific devices.
|
||||
* @param tags - List of tags you want to attach.
|
||||
* @throws TagManagementException if something goes wrong while deleting the device-tag mapping.
|
||||
*/
|
||||
void deleteDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tags)
|
||||
throws TagManagementException, BadRequestException;
|
||||
}
|
@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.service;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.*;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.dao.*;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TagManagementProviderServiceImpl implements TagManagementProviderService {
|
||||
private static final Log log = LogFactory.getLog(TagManagementProviderServiceImpl.class);
|
||||
|
||||
private final TagDAO tagDAO;
|
||||
|
||||
public TagManagementProviderServiceImpl() {
|
||||
this.tagDAO = DeviceManagementDAOFactory.getTagDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTags(List<Tag> tags) throws TagManagementException, BadRequestException {
|
||||
if (tags == null || tags.isEmpty()) {
|
||||
String msg = "Received incomplete data for tags";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
for (Tag tag : tags) {
|
||||
if (tag.getName() == null) {
|
||||
String msg = "Tag name cannot be null";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Starting creating Tags.");
|
||||
}
|
||||
tagDAO.addTags(tags, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding tags to database.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in creating tags.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getAllTags() throws TagManagementException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
List<Tag> tags = tagDAO.getTags(tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
return tags;
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while retrieving tags.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in retrieving tags.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getTagById(int tagId) throws TagManagementException, TagNotFoundException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Tag tag = tagDAO.getTagById(tagId, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
if (tag == null) {
|
||||
String msg = "Tag with ID " + tagId + " not found.";
|
||||
throw new TagNotFoundException(msg);
|
||||
}
|
||||
return tag;
|
||||
} catch (TransactionManagementException | TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while retrieving the tag with ID: " + tagId;
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getTagByName(String tagName) throws TagManagementException, TagNotFoundException, BadRequestException {
|
||||
if (tagName == null || tagName.trim().isEmpty()) {
|
||||
String msg = "Tag name cannot be null or empty.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Tag tag = tagDAO.getTagByName(tagName, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
if (tag == null) {
|
||||
String msg = "Tag with name " + tagName + " not found.";
|
||||
throw new TagNotFoundException(msg);
|
||||
}
|
||||
return tag;
|
||||
} catch (TransactionManagementException | TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while retrieving the tag with name: " + tagName;
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateTag(Tag tag) throws TagManagementException, TagNotFoundException, BadRequestException {
|
||||
if (tag == null || tag.getName() == null) {
|
||||
String msg = "Received incomplete data for tag update";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Tag existingTag = tagDAO.getTagById(tag.getId(), tenantId);
|
||||
if (existingTag == null) {
|
||||
String msg = "Tag with ID: " + tag.getId() + " does not exist.";
|
||||
log.error(msg);
|
||||
throw new TagNotFoundException(msg);
|
||||
}
|
||||
Tag tagWithName = tagDAO.getTagByName(tag.getName(), tenantId);
|
||||
if (tagWithName != null && tagWithName.getId() != tag.getId()) {
|
||||
String msg = "Tag with name: " + tag.getName() + " already exists.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
tagDAO.updateTag(tag, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TagManagementDAOException | TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while updating the tag with ID: " + tag.getId();
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteTag(int tagId) throws TagManagementException, TagNotFoundException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Tag existingTag = tagDAO.getTagById(tagId, tenantId);
|
||||
if (existingTag == null) {
|
||||
String msg = "Tag with ID: " + tagId + " does not exist.";
|
||||
log.error(msg);
|
||||
throw new TagNotFoundException(msg);
|
||||
}
|
||||
tagDAO.deleteTag(tagId, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TagManagementDAOException | TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting the tag with ID: " + tagId;
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tags)
|
||||
throws TagManagementException, BadRequestException {
|
||||
if (deviceIdentifiers == null || deviceType == null || tags == null) {
|
||||
String msg = "Received incomplete data for device tag mapping.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
TagMappingDTO tagMappingDto = new TagMappingDTO(deviceIdentifiers, deviceType, tags);
|
||||
List<Tag> tagList = new ArrayList<>();
|
||||
for (String tagName : tagMappingDto.getTags()) {
|
||||
Tag tag = new Tag();
|
||||
tag.setName(tagName);
|
||||
tagList.add(tag);
|
||||
}
|
||||
|
||||
tagDAO.addTags(tagList, tenantId);
|
||||
tagDAO.addDeviceTagMapping(tagMappingDto.getDeviceIdentifiers(), tagMappingDto.getDeviceType(),
|
||||
tagMappingDto.getTags(), tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TagManagementDAOException e) {
|
||||
if (e.isUniqueConstraintViolation()) {
|
||||
String msg = "Tag is already mapped to this device.";
|
||||
log.info(msg, e);
|
||||
throw new BadRequestException(msg);
|
||||
} else {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding device tag mapping.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
}
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding device tag mapping.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceTagMapping(List<String> deviceIdentifiers, String deviceType, List<String> tags) throws TagManagementException, BadRequestException {
|
||||
if (deviceIdentifiers == null || deviceType == null || tags == null) {
|
||||
String msg = "Received incomplete data for device tag mapping.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
TagMappingDTO tagMappingDto = new TagMappingDTO(deviceIdentifiers, deviceType, tags);
|
||||
tagDAO.deleteDeviceTagMapping(tagMappingDto.getDeviceIdentifiers(), tagMappingDto.getDeviceType(),
|
||||
tagMappingDto.getTags(), tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TagManagementDAOException | TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting device tag mappings.";
|
||||
log.error(msg, e);
|
||||
throw new TagManagementException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.dao;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.TestUtils;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.common.TestDataHolder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TagPersistTests extends BaseDeviceManagementTest {
|
||||
|
||||
private TagDAO tagDAO;
|
||||
private static final Log log = LogFactory.getLog(TagPersistTests.class);
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
initDataSource();
|
||||
tagDAO = DeviceManagementDAOFactory.getTagDAO();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTag() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
tagDAO.addTags(TestUtils.createTagList3(), TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
log.debug("Tags added to the database");
|
||||
Tag tag = tagDAO.getTagByName("tag1", TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
Assert.assertNotNull(tag, "Tag should be added and retrieved.");
|
||||
Assert.assertEquals(tag.getName(), "tag1", "Tag name mismatch.");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding tag list type.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addTag")
|
||||
public void updateTag() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
String updatedDescription = "Updated Description";
|
||||
Tag tag = tagDAO.getTagByName("tag1", TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
Tag tagToUpdate = new Tag(tag.getId(), tag.getName(), updatedDescription);
|
||||
tagDAO.updateTag(tagToUpdate, TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
log.debug("Tag updated in the database");
|
||||
tag = tagDAO.getTagByName("tag1", TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
Assert.assertEquals(tag.getDescription(), updatedDescription, "Tag description mismatch.");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while updating tag.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateTag")
|
||||
public void deleteTag() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
tagDAO.deleteTag(1, TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
log.debug("Tag deleted from the database");
|
||||
Tag deletedTag = tagDAO.getTagById(1, TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
Assert.assertNull(deletedTag, "Tag should be deleted.");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting tag.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"deleteTag"})
|
||||
public void getTags() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
List<Tag> tags = tagDAO.getTags(TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
log.debug("Tags retrieved successfully.");
|
||||
Assert.assertEquals(tags.size(), 2);
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while retrieving tags.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"getTags"})
|
||||
public void getTagByName() {
|
||||
try {
|
||||
String tagName = "tag2";
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
Tag tag = tagDAO.getTagByName(tagName, TestDataHolder.ALTERNATE_TENANT_ID);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
log.debug("Tag " + tagName + " retrieved successfully.");
|
||||
Assert.assertEquals(tag.getName(), "tag2");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while retrieving tag by Id.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagByName")
|
||||
public void addTagsForAlternateTenant() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
//Here, adding a same tag name for a separate tenant is tested.
|
||||
tagDAO.addTags(TestUtils.createTagList3(), TestDataHolder.ALTERNATE_TENANT_ID_1);
|
||||
log.debug("Tags added for a alternate tenant");
|
||||
List<Tag> tagList = tagDAO.getTags(TestDataHolder.ALTERNATE_TENANT_ID_1);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
Assert.assertEquals(tagList.size(), 2, "Tag count mismatch.");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding tags for a different tenant.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "addTagsForAlternateTenant")
|
||||
public void getTagsOfAlternateTenant() {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
List<Tag> tagList = tagDAO.getTags(TestDataHolder.ALTERNATE_TENANT_ID_1);
|
||||
log.debug("Tags retrieved for a alternate tenant " + TestDataHolder.ALTERNATE_TENANT_ID_1);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
Assert.assertEquals(tagList.size(), 2, "Tag count mismatch.");
|
||||
} catch (TagManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while adding tags for a different tenant.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while initiating transaction.";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.service;
|
||||
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.Tag;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.TagManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.TagMappingDTO;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.tag.mgt.TagNotFoundException;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.TestUtils;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TagManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||
|
||||
private TagManagementProviderService tagManagementProviderService;
|
||||
|
||||
public static final String DEVICE_ID_1 = "100001";
|
||||
public static final String DEVICE_ID_2 = "100002";
|
||||
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
tagManagementProviderService = new TagManagementProviderServiceImpl();
|
||||
RealmService realmService = new InMemoryRealmService();
|
||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||
realmService.getTenantManager().getSuperTenantDomain();
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {TagManagementException.class, BadRequestException.class})
|
||||
public void createTagsNull() throws TagManagementException, BadRequestException {
|
||||
tagManagementProviderService.addTags(null);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {TagManagementException.class, BadRequestException.class}, dependsOnMethods = "createTagsNull")
|
||||
public void createTagsNameNullError() throws TagManagementException, BadRequestException {
|
||||
tagManagementProviderService.addTags(TestUtils.createTagList1());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "createTagsNameNullError")
|
||||
public void createTags() throws TagManagementException, BadRequestException {
|
||||
tagManagementProviderService.addTags(TestUtils.createTagList2());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {TagNotFoundException.class, BadRequestException.class, TagManagementException.class})
|
||||
public void updateTagsNotFound() throws TagNotFoundException, TagManagementException, BadRequestException {
|
||||
String updateDescString = "This tag is updated";
|
||||
tagManagementProviderService.updateTag(new Tag(10,"tag10", updateDescString));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateTagsNotFound")
|
||||
public void updateTags() throws TagNotFoundException, TagManagementException, BadRequestException {
|
||||
String updateDescString = "This tag is updated";
|
||||
tagManagementProviderService.updateTag(new Tag(1,"tag1", updateDescString));
|
||||
Tag tag = tagManagementProviderService.getTagById(1);
|
||||
Assert.assertEquals(tag.getDescription(), updateDescString);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "updateTags", expectedExceptions = {TagNotFoundException.class})
|
||||
public void getTagNotFoundById() throws TagManagementException, TagNotFoundException {
|
||||
tagManagementProviderService.getTagById(10);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagNotFoundById", expectedExceptions = {BadRequestException.class})
|
||||
public void getTagNotFoundByNameNull() throws TagManagementException, TagNotFoundException, BadRequestException {
|
||||
tagManagementProviderService.getTagByName(null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagNotFoundByNameNull", expectedExceptions = {TagNotFoundException.class})
|
||||
public void getTagNotFoundByName() throws TagManagementException, TagNotFoundException, BadRequestException {
|
||||
tagManagementProviderService.getTagByName("tag10");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagNotFoundByName")
|
||||
public void getTagById() throws TagManagementException, TagNotFoundException {
|
||||
Tag tag = tagManagementProviderService.getTagById(2);
|
||||
Assert.assertEquals(tag.getName(), TestUtils.getTag2().getName());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagById")
|
||||
public void getTagByName() throws TagManagementException, TagNotFoundException, BadRequestException {
|
||||
Tag tag = tagManagementProviderService.getTagByName("tag2");
|
||||
Assert.assertEquals(tag.getName(), TestUtils.getTag2().getName());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getTagByName")
|
||||
public void getTags() throws TagManagementException {
|
||||
List<Tag> tags = tagManagementProviderService.getAllTags();
|
||||
Assert.assertEquals(tags.size(), 3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {TagNotFoundException.class}, dependsOnMethods = "getTags")
|
||||
public void deleteTagNotExists() throws TagManagementException, TagNotFoundException {
|
||||
tagManagementProviderService.deleteTag(10);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "deleteTagNotExists")
|
||||
public void deleteTag() throws TagManagementException, TagNotFoundException {
|
||||
tagManagementProviderService.deleteTag(1);
|
||||
List<Tag> tags = tagManagementProviderService.getAllTags();
|
||||
Assert.assertEquals(tags.size(), 2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "deleteTag")
|
||||
public void createTagMappingsNull() throws TagManagementException, BadRequestException {
|
||||
tagManagementProviderService.addDeviceTagMapping(null, null, null);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "createTagMappingsNull")
|
||||
public void createTagsMappingsNullDeviceIdentifiers() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.addDeviceTagMapping(null, DEVICE_TYPE,
|
||||
new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "createTagsMappingsNullDeviceIdentifiers")
|
||||
public void createTagsMappingsNullDeviceType() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.addDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
null, new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "createTagsMappingsNullDeviceType")
|
||||
public void createTagsMappingsNullTags() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.addDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
DEVICE_TYPE, null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "createTagsMappingsNullTags")
|
||||
public void createTagsMappings() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.addDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
DEVICE_TYPE, new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "createTagsMappings")
|
||||
public void deleteTagMappingsNull() throws TagManagementException, BadRequestException {
|
||||
tagManagementProviderService.deleteDeviceTagMapping(null, null, null);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "deleteTagMappingsNull")
|
||||
public void deleteTagsMappingsNullDeviceIdentifiers() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.deleteDeviceTagMapping(null, DEVICE_TYPE,
|
||||
new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "deleteTagsMappingsNullDeviceIdentifiers")
|
||||
public void deleteTagsMappingsNullDeviceType() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.deleteDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
null, new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {BadRequestException.class}, dependsOnMethods = "deleteTagsMappingsNullDeviceType")
|
||||
public void deleteTagsMappingsNullTags() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.deleteDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
DEVICE_TYPE, null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "deleteTagsMappingsNullTags")
|
||||
public void deleteTagsMappings() throws TagManagementException, DeviceManagementException {
|
||||
tagManagementProviderService.deleteDeviceTagMapping(new ArrayList<>(Arrays.asList(DEVICE_ID_1, DEVICE_ID_2)),
|
||||
DEVICE_TYPE, new ArrayList<>(Arrays.asList("tag1", "tag2")));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue