mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' into android-feature
This commit is contained in:
commit
0f8c3e22e6
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
<a href='https://opensource.org/licenses/Apache-2.0'><img src='https://img.shields.io/badge/License-Apache%202.0-blue.svg'></a><br/>
|
<a href='https://opensource.org/licenses/Apache-2.0'><img src='https://img.shields.io/badge/License-Apache%202.0-blue.svg'></a><br/>
|
||||||
|
|
||||||
<a href='#'><img src="https://storage.googleapis.com/cdn-entgra/build-status/device-mgt-core/icon.svg"></a>
|
<a href='#'><img src="https://builder.entgra.net/buildStatus/icon?job=device-mgt-core"></a>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>analytics-mgt</artifactId>
|
<artifactId>analytics-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -40,11 +40,11 @@ public interface KeyManagerService {
|
|||||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
@Path("/token")
|
@Path("/token")
|
||||||
Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader,
|
Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader,
|
||||||
@FormParam("client_id") String clientId,
|
|
||||||
@FormParam("client_secret") String clientSecret,
|
|
||||||
@FormParam("refresh_token") String refreshToken,
|
@FormParam("refresh_token") String refreshToken,
|
||||||
@FormParam("scope") String scope,
|
@FormParam("scope") String scope,
|
||||||
@FormParam("grant_type") String grantType,
|
@FormParam("grant_type") String grantType,
|
||||||
@FormParam("assertion") String assertion,
|
@FormParam("assertion") String assertion,
|
||||||
@FormParam("admin_access_token") String admin_access_token);
|
@FormParam("admin_access_token") String admin_access_token,
|
||||||
|
@FormParam("username") String username,
|
||||||
|
@FormParam("password") String password);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,13 +63,13 @@ public class KeyManagerServiceImpl implements KeyManagerService {
|
|||||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
@Path("/token")
|
@Path("/token")
|
||||||
public Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader,
|
public Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader,
|
||||||
@FormParam("client_id") String clientId,
|
|
||||||
@FormParam("client_secret") String clientSecret,
|
|
||||||
@FormParam("refresh_token") String refreshToken,
|
@FormParam("refresh_token") String refreshToken,
|
||||||
@FormParam("scope") String scope,
|
@FormParam("scope") String scope,
|
||||||
@FormParam("grant_type") String grantType,
|
@FormParam("grant_type") String grantType,
|
||||||
@FormParam("assertion") String assertion,
|
@FormParam("assertion") String assertion,
|
||||||
@FormParam("admin_access_token") String admin_access_token) {
|
@FormParam("admin_access_token") String admin_access_token,
|
||||||
|
@FormParam("username") String username,
|
||||||
|
@FormParam("password") String password) {
|
||||||
try {
|
try {
|
||||||
if (basicAuthHeader == null) {
|
if (basicAuthHeader == null) {
|
||||||
String msg = "Invalid credentials. Make sure your API call is invoked with a Basic Authorization header.";
|
String msg = "Invalid credentials. Make sure your API call is invoked with a Basic Authorization header.";
|
||||||
@ -80,7 +80,7 @@ public class KeyManagerServiceImpl implements KeyManagerService {
|
|||||||
TokenResponse resp = keyMgtService.generateAccessToken(
|
TokenResponse resp = keyMgtService.generateAccessToken(
|
||||||
new TokenRequest(encodedClientCredentials.split(":")[0],
|
new TokenRequest(encodedClientCredentials.split(":")[0],
|
||||||
encodedClientCredentials.split(":")[1], refreshToken, scope,
|
encodedClientCredentials.split(":")[1], refreshToken, scope,
|
||||||
grantType, assertion,admin_access_token));
|
grantType, assertion, admin_access_token, username, password));
|
||||||
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
|
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
|
||||||
} catch (KeyMgtException e) {
|
} catch (KeyMgtException e) {
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -26,9 +26,11 @@ public class TokenRequest {
|
|||||||
private String grantType;
|
private String grantType;
|
||||||
private String assertion;
|
private String assertion;
|
||||||
private String admin_access_token;
|
private String admin_access_token;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
public TokenRequest(String clientId, String clientSecret, String refreshToken, String scope, String grantType,
|
public TokenRequest(String clientId, String clientSecret, String refreshToken, String scope, String grantType,
|
||||||
String assertion, String admin_access_token) {
|
String assertion, String admin_access_token, String username, String password) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.clientSecret = clientSecret;
|
this.clientSecret = clientSecret;
|
||||||
this.refreshToken = refreshToken;
|
this.refreshToken = refreshToken;
|
||||||
@ -36,6 +38,8 @@ public class TokenRequest {
|
|||||||
this.grantType = grantType;
|
this.grantType = grantType;
|
||||||
this.assertion = assertion;
|
this.assertion = assertion;
|
||||||
this.admin_access_token = admin_access_token;
|
this.admin_access_token = admin_access_token;
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientId() {
|
public String getClientId() {
|
||||||
@ -93,4 +97,20 @@ public class TokenRequest {
|
|||||||
public void setAdminAccessToken(String admin_access_token) {
|
public void setAdminAccessToken(String admin_access_token) {
|
||||||
this.admin_access_token = admin_access_token;
|
this.admin_access_token = admin_access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,13 @@ public class TokenResponse {
|
|||||||
this.expires_in = expires_in;
|
this.expires_in = expires_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TokenResponse(String access_token, String scope, String token_type, int expires_in) {
|
||||||
|
this.access_token = access_token;
|
||||||
|
this.scope = scope;
|
||||||
|
this.token_type = token_type;
|
||||||
|
this.expires_in = expires_in;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAccessToken() {
|
public String getAccessToken() {
|
||||||
return access_token;
|
return access_token;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,49 +159,34 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String tenantDomain = MultitenantUtils.getTenantDomain(application.getOwner());
|
String tenantDomain = MultitenantUtils.getTenantDomain(application.getOwner());
|
||||||
|
|
||||||
String username, password;
|
|
||||||
if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) {
|
|
||||||
kmConfig = getKeyManagerConfig();
|
kmConfig = getKeyManagerConfig();
|
||||||
username = kmConfig.getAdminUsername();
|
String appTokenEndpoint = kmConfig.getServerUrl() + KeyMgtConstants.OAUTH2_TOKEN_ENDPOINT;
|
||||||
password = kmConfig.getAdminUsername();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
username = getRealmService()
|
|
||||||
.getTenantUserRealm(-1234).getRealmConfiguration()
|
|
||||||
.getRealmProperty("reserved_tenant_user_username") + "@" + tenantDomain;
|
|
||||||
password = getRealmService()
|
|
||||||
.getTenantUserRealm(-1234).getRealmConfiguration()
|
|
||||||
.getRealmProperty("reserved_tenant_user_password");
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
msg = "Error while loading user realm configuration";
|
|
||||||
log.error(msg);
|
|
||||||
throw new KeyMgtException(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RequestBody appTokenPayload;
|
RequestBody appTokenPayload;
|
||||||
switch (tokenRequest.getGrantType()) {
|
switch (tokenRequest.getGrantType()) {
|
||||||
case "client_credentials":
|
case "client_credentials":
|
||||||
|
appTokenPayload = new FormBody.Builder()
|
||||||
|
.add("grant_type", "client_credentials")
|
||||||
|
.add("scope", tokenRequest.getScope()).build();
|
||||||
|
break;
|
||||||
case "password":
|
case "password":
|
||||||
appTokenPayload = new FormBody.Builder()
|
appTokenPayload = new FormBody.Builder()
|
||||||
.add("grant_type", "password")
|
.add("grant_type", "password")
|
||||||
.add("username", username)
|
.add("username", tokenRequest.getUsername())
|
||||||
.add("password", password)
|
.add("password", tokenRequest.getPassword())
|
||||||
.add("scope", tokenRequest.getScope()).build();
|
.add("scope", tokenRequest.getScope()).build();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "refresh_token":
|
case "refresh_token":
|
||||||
appTokenPayload = new FormBody.Builder()
|
appTokenPayload = new FormBody.Builder()
|
||||||
.add("grant_type", "refresh_token")
|
.add("grant_type", "refresh_token")
|
||||||
.add("refresh_token", tokenRequest.getRefreshToken())
|
.add("refresh_token", tokenRequest.getRefreshToken()).build();
|
||||||
.add("scope", tokenRequest.getScope()).build();
|
|
||||||
break;
|
break;
|
||||||
case "urn:ietf:params:oauth:grant-type:jwt-bearer":
|
case "urn:ietf:params:oauth:grant-type:jwt-bearer":
|
||||||
appTokenPayload = new FormBody.Builder()
|
appTokenPayload = new FormBody.Builder()
|
||||||
.add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
|
.add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
|
||||||
.add("assertion", tokenRequest.getAssertion())
|
.add("assertion", tokenRequest.getAssertion())
|
||||||
.add("scope", tokenRequest.getScope()).build();
|
.add("scope", tokenRequest.getScope()).build();
|
||||||
|
appTokenEndpoint += "?tenantDomain=carbon.super";
|
||||||
break;
|
break;
|
||||||
case "access_token":
|
case "access_token":
|
||||||
appTokenPayload = new FormBody.Builder()
|
appTokenPayload = new FormBody.Builder()
|
||||||
@ -216,8 +201,6 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
kmConfig = getKeyManagerConfig();
|
|
||||||
String appTokenEndpoint = kmConfig.getServerUrl() + KeyMgtConstants.OAUTH2_TOKEN_ENDPOINT;
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(appTokenEndpoint)
|
.url(appTokenEndpoint)
|
||||||
.addHeader(KeyMgtConstants.AUTHORIZATION_HEADER, Credentials.basic(tokenRequest.getClientId(), tokenRequest.getClientSecret()))
|
.addHeader(KeyMgtConstants.AUTHORIZATION_HEADER, Credentials.basic(tokenRequest.getClientId(), tokenRequest.getClientSecret()))
|
||||||
@ -239,12 +222,19 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|||||||
.getTenantManager().getTenantId(tenantDomain);
|
.getTenantManager().getTenantId(tenantDomain);
|
||||||
accessToken = tenantId + "_" + responseObj.getString("access_token");
|
accessToken = tenantId + "_" + responseObj.getString("access_token");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tokenRequest.getGrantType().equals("client_credentials")) {
|
||||||
|
return new TokenResponse(accessToken,
|
||||||
|
responseObj.getString("scope"),
|
||||||
|
responseObj.getString("token_type"),
|
||||||
|
responseObj.getInt("expires_in"));
|
||||||
|
} else {
|
||||||
return new TokenResponse(accessToken,
|
return new TokenResponse(accessToken,
|
||||||
responseObj.getString("refresh_token"),
|
responseObj.getString("refresh_token"),
|
||||||
responseObj.getString("scope"),
|
responseObj.getString("scope"),
|
||||||
responseObj.getString("token_type"),
|
responseObj.getString("token_type"),
|
||||||
responseObj.getInt("expires_in"));
|
responseObj.getInt("expires_in"));
|
||||||
|
}
|
||||||
} catch (APIManagementException e) {
|
} catch (APIManagementException e) {
|
||||||
msg = "Error occurred while retrieving application";
|
msg = "Error occurred while retrieving application";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import io.entgra.application.mgt.core.util.DAOUtil;
|
|||||||
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
|
import io.entgra.application.mgt.core.util.Constants;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -149,7 +150,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
}
|
}
|
||||||
sql += "WHERE AP_APP.TENANT_ID = ? ";
|
sql += "WHERE AP_APP.TENANT_ID = ? ";
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
sql += "AND AP_APP.TYPE = ? ";
|
sql += "AND AP_APP.TYPE = ? ";
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
@ -204,7 +205,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
int paramIndex = 1;
|
int paramIndex = 1;
|
||||||
stmt.setInt(paramIndex++, tenantId);
|
stmt.setInt(paramIndex++, tenantId);
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
stmt.setString(paramIndex++, filter.getAppType());
|
stmt.setString(paramIndex++, filter.getAppType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
|||||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||||
|
import io.entgra.application.mgt.core.util.Constants;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -94,7 +95,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
|||||||
|| StringUtils.isNotEmpty(filter.getAppReleaseType())) {
|
|| StringUtils.isNotEmpty(filter.getAppReleaseType())) {
|
||||||
sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
|
sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
sql += "AND AP_APP.TYPE = ? ";
|
sql += "AND AP_APP.TYPE = ? ";
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
@ -145,7 +146,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
|||||||
Connection conn = this.getDBConnection();
|
Connection conn = this.getDBConnection();
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
int paramIndex = 1;
|
int paramIndex = 1;
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
stmt.setString(paramIndex++, filter.getAppType());
|
stmt.setString(paramIndex++, filter.getAppType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import io.entgra.application.mgt.common.dto.ApplicationDTO;
|
|||||||
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
import io.entgra.application.mgt.common.exception.DBConnectionException;
|
||||||
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.application.mgt.core.util.DAOUtil;
|
import io.entgra.application.mgt.core.util.DAOUtil;
|
||||||
|
import io.entgra.application.mgt.core.util.Constants;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -93,7 +94,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
|
|||||||
|| StringUtils.isNotEmpty(filter.getAppReleaseType())) {
|
|| StringUtils.isNotEmpty(filter.getAppReleaseType())) {
|
||||||
sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
|
sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
sql += "AND AP_APP.TYPE = ? ";
|
sql += "AND AP_APP.TYPE = ? ";
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
@ -144,7 +145,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
|
|||||||
Connection conn = this.getDBConnection();
|
Connection conn = this.getDBConnection();
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
int paramIndex = 1;
|
int paramIndex = 1;
|
||||||
if (StringUtils.isNotEmpty(filter.getAppType())) {
|
if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) {
|
||||||
stmt.setString(paramIndex++, filter.getAppType());
|
stmt.setString(paramIndex++, filter.getAppType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
if (StringUtils.isNotEmpty(filter.getAppName())) {
|
||||||
|
|||||||
@ -2932,7 +2932,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
if (!StringUtils.isEmpty(appType)) {
|
if (!StringUtils.isEmpty(appType)) {
|
||||||
boolean isValidAppType = false;
|
boolean isValidAppType = false;
|
||||||
for (ApplicationType applicationType : ApplicationType.values()) {
|
for (ApplicationType applicationType : ApplicationType.values()) {
|
||||||
if (applicationType.toString().equalsIgnoreCase(appType)) {
|
if (applicationType.toString().equalsIgnoreCase(appType) || Constants.ALL.equalsIgnoreCase(appType)) {
|
||||||
isValidAppType = true;
|
isValidAppType = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3434,6 +3434,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
int deviceTypeId = -1;
|
int deviceTypeId = -1;
|
||||||
String appName;
|
String appName;
|
||||||
|
int appNameLength = 20;
|
||||||
List<String> appCategories;
|
List<String> appCategories;
|
||||||
List<String> unrestrictedRoles;
|
List<String> unrestrictedRoles;
|
||||||
|
|
||||||
@ -3445,6 +3446,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
|
if (appName.length() > appNameLength) {
|
||||||
|
String msg = "Application name must be less than or equal to 20 characters in length.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
appCategories = applicationWrapper.getCategories();
|
appCategories = applicationWrapper.getCategories();
|
||||||
if (appCategories == null) {
|
if (appCategories == null) {
|
||||||
String msg = "Application category can't be null.";
|
String msg = "Application category can't be null.";
|
||||||
@ -3477,6 +3483,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
|
if (appName.length() > appNameLength) {
|
||||||
|
String msg = "Application name must be less than or equal to 20 characters in length.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
appCategories = webAppWrapper.getCategories();
|
appCategories = webAppWrapper.getCategories();
|
||||||
if (appCategories == null) {
|
if (appCategories == null) {
|
||||||
String msg = "Web Clip category can't be null.";
|
String msg = "Web Clip category can't be null.";
|
||||||
@ -3510,6 +3521,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
|
if (appName.length() > appNameLength) {
|
||||||
|
String msg = "Application name must be less than or equal to 20 characters in length.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
appCategories = publicAppWrapper.getCategories();
|
appCategories = publicAppWrapper.getCategories();
|
||||||
if (appCategories == null) {
|
if (appCategories == null) {
|
||||||
String msg = "Application category can't be null.";
|
String msg = "Application category can't be null.";
|
||||||
@ -3542,6 +3558,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
|
if (appName.length() > appNameLength) {
|
||||||
|
String msg = "Application name must be less than or equal to 20 characters in length.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
appCategories = customAppWrapper.getCategories();
|
appCategories = customAppWrapper.getCategories();
|
||||||
if (appCategories == null) {
|
if (appCategories == null) {
|
||||||
String msg = "Application category can't be null.";
|
String msg = "Application category can't be null.";
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -322,7 +322,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished);
|
@QueryParam("is-published") boolean isPublished);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/web-app")
|
@Path("/web-app")
|
||||||
@ -366,7 +366,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -411,7 +411,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -457,7 +457,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -512,7 +512,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -567,7 +567,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -617,7 +617,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -672,7 +672,7 @@ public interface ApplicationManagementPublisherAPI {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished
|
@QueryParam("is-published") boolean isPublished
|
||||||
);
|
);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
|
|||||||
@ -318,7 +318,7 @@ public interface SPApplicationService {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished);
|
@QueryParam("is-published") boolean isPublished);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to register an APIM application for tenant domain.
|
* This method is used to register an APIM application for tenant domain.
|
||||||
@ -345,7 +345,7 @@ public interface SPApplicationService {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished);
|
@QueryParam("is-published") boolean isPublished);
|
||||||
|
|
||||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
|
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
|
||||||
@POST
|
@POST
|
||||||
@ -369,7 +369,7 @@ public interface SPApplicationService {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished);
|
@QueryParam("is-published") boolean isPublished);
|
||||||
|
|
||||||
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
|
@Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
|
||||||
@POST
|
@POST
|
||||||
@ -392,5 +392,5 @@ public interface SPApplicationService {
|
|||||||
name = "isPublished",
|
name = "isPublished",
|
||||||
value = "Published state of the application"
|
value = "Published state of the application"
|
||||||
)
|
)
|
||||||
@QueryParam("isPublished") boolean isPublished);
|
@QueryParam("is-published") boolean isPublished);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,12 +157,12 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
@PathParam("appId") int applicatioId);
|
@PathParam("appId") int applicatioId);
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/tags/{tagName}")
|
@Path("/tags")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
produces = MediaType.APPLICATION_JSON,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "GET",
|
httpMethod = "DELETE",
|
||||||
value = "Delete application tag",
|
value = "Delete application tag",
|
||||||
notes = "This will delete application tag",
|
notes = "This will delete application tag",
|
||||||
tags = "Application Management",
|
tags = "Application Management",
|
||||||
@ -185,10 +185,10 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
})
|
})
|
||||||
Response deleteTag(
|
Response deleteTag(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "tagName",
|
name = "tag-name",
|
||||||
value = "Tag Name",
|
value = "Tag Name",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("tagName") String tagName
|
@QueryParam("tag-name") String tagName
|
||||||
);
|
);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@ -273,7 +273,7 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/categories/{categoryName}")
|
@Path("/categories")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
@ -301,10 +301,10 @@ public interface ApplicationManagementPublisherAdminAPI {
|
|||||||
})
|
})
|
||||||
Response deleteCategory(
|
Response deleteCategory(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "categoryName",
|
name = "category-name",
|
||||||
value = "Category Name",
|
value = "Category Name",
|
||||||
required = true)
|
required = true)
|
||||||
@PathParam("categoryName") String categoryName
|
@QueryParam("category-name") String categoryName
|
||||||
);
|
);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
|
|||||||
@ -260,7 +260,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
@PathParam("deviceType") String deviceTypeName,
|
@PathParam("deviceType") String deviceTypeName,
|
||||||
@PathParam("appId") int appId,
|
@PathParam("appId") int appId,
|
||||||
EntAppReleaseWrapper entAppReleaseWrapper,
|
EntAppReleaseWrapper entAppReleaseWrapper,
|
||||||
@QueryParam("isPublished") boolean isPublished) {
|
@QueryParam("is-published") boolean isPublished) {
|
||||||
try {
|
try {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
applicationManager.validateEntAppReleaseCreatingRequest(entAppReleaseWrapper, deviceTypeName);
|
applicationManager.validateEntAppReleaseCreatingRequest(entAppReleaseWrapper, deviceTypeName);
|
||||||
@ -284,7 +284,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
public Response createPubAppRelease(
|
public Response createPubAppRelease(
|
||||||
@PathParam("deviceType") String deviceTypeName,
|
@PathParam("deviceType") String deviceTypeName,
|
||||||
@PathParam("appId") int appId,
|
@PathParam("appId") int appId,
|
||||||
PublicAppReleaseWrapper publicAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) {
|
PublicAppReleaseWrapper publicAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
@ -312,7 +312,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
@Override
|
@Override
|
||||||
public Response createWebAppRelease(
|
public Response createWebAppRelease(
|
||||||
@PathParam("appId") int appId,
|
@PathParam("appId") int appId,
|
||||||
WebAppReleaseWrapper webAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) {
|
WebAppReleaseWrapper webAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
|
||||||
try {
|
try {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper);
|
applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper);
|
||||||
@ -340,7 +340,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
public Response createCustomAppRelease(
|
public Response createCustomAppRelease(
|
||||||
@PathParam("deviceType") String deviceTypeName,
|
@PathParam("deviceType") String deviceTypeName,
|
||||||
@PathParam("appId") int appId,
|
@PathParam("appId") int appId,
|
||||||
CustomAppReleaseWrapper customAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) {
|
CustomAppReleaseWrapper customAppReleaseWrapper, @QueryParam("is-published") boolean isPublished) {
|
||||||
try {
|
try {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName);
|
applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName);
|
||||||
@ -371,19 +371,28 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
if (appName == null) {
|
if (appName == null) {
|
||||||
String msg = "Invalid app name, appName query param cannot be empty/null.";
|
String msg = "Invalid app name, appName query param cannot be empty/null.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
|
}
|
||||||
|
if (appName.length() > 20) {
|
||||||
|
String msg = "Invalid app name, maximum length of the application name should be 20 characters.";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
}
|
}
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
if (applicationManager.isExistingAppName(appName, deviceType)) {
|
if (applicationManager.isExistingAppName(appName, deviceType)) {
|
||||||
return Response.status(Response.Status.CONFLICT).build();
|
String msg = "Invalid app name, app name already exists.";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.CONFLICT).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
} catch (BadRequestException e) {
|
} catch (BadRequestException e) {
|
||||||
log.error("Found invalid device type to check application existence.", e);
|
String msg = "Found invalid device type to check application existence.";
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
log.error("Internal Error occurred while checking the application existence.", e);
|
String msg = "Internal Error occurred while checking the application existence.";
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -295,7 +295,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
|
|||||||
@Override
|
@Override
|
||||||
public Response createEntApp(@PathParam("identity-server-id") int identityServerId,
|
public Response createEntApp(@PathParam("identity-server-id") int identityServerId,
|
||||||
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
|
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app,
|
||||||
@QueryParam("isPublished") boolean isPublished) {
|
@QueryParam("is-published") boolean isPublished) {
|
||||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
|
|||||||
@Override
|
@Override
|
||||||
public Response createPubApp(@PathParam("identity-server-id") int identityServerId,
|
public Response createPubApp(@PathParam("identity-server-id") int identityServerId,
|
||||||
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
|
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app,
|
||||||
@QueryParam("isPublished") boolean isPublished) {
|
@QueryParam("is-published") boolean isPublished) {
|
||||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
|
|||||||
@Override
|
@Override
|
||||||
public Response createWebApp(@PathParam("identity-server-id") int identityServerId,
|
public Response createWebApp(@PathParam("identity-server-id") int identityServerId,
|
||||||
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
|
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app,
|
||||||
@QueryParam("isPublished") boolean isPublished) {
|
@QueryParam("is-published") boolean isPublished) {
|
||||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
|
|||||||
@Override
|
@Override
|
||||||
public Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
|
public Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
|
||||||
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
|
@PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app,
|
||||||
@QueryParam("isPublished") boolean isPublished) {
|
@QueryParam("is-published") boolean isPublished) {
|
||||||
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
return createSPApplication(identityServerId, serviceProviderId, app, isPublished);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -104,9 +104,9 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
|
|||||||
@DELETE
|
@DELETE
|
||||||
@Override
|
@Override
|
||||||
@Consumes(MediaType.WILDCARD)
|
@Consumes(MediaType.WILDCARD)
|
||||||
@Path("/tags/{tagName}")
|
@Path("/tags")
|
||||||
public Response deleteTag(
|
public Response deleteTag(
|
||||||
@PathParam("tagName") String tagName) {
|
@QueryParam("tag-name") String tagName) {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
try {
|
try {
|
||||||
applicationManager.deleteTag(tagName);
|
applicationManager.deleteTag(tagName);
|
||||||
@ -169,9 +169,9 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa
|
|||||||
@DELETE
|
@DELETE
|
||||||
@Override
|
@Override
|
||||||
@Consumes(MediaType.WILDCARD)
|
@Consumes(MediaType.WILDCARD)
|
||||||
@Path("/categories/{categoryName}")
|
@Path("/categories")
|
||||||
public Response deleteCategory(
|
public Response deleteCategory(
|
||||||
@PathParam("categoryName") String categoryName) {
|
@QueryParam("category-name") String categoryName) {
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
try {
|
try {
|
||||||
applicationManager.deleteCategory(categoryName);
|
applicationManager.deleteCategory(categoryName);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -50,11 +50,22 @@ public class RequestValidationUtil {
|
|||||||
case "REMOVED":
|
case "REMOVED":
|
||||||
case "BLOCKED":
|
case "BLOCKED":
|
||||||
case "CREATED":
|
case "CREATED":
|
||||||
|
case "CONFIGURED":
|
||||||
|
case "READY_TO_CONNECT":
|
||||||
|
case "RETURN_PENDING":
|
||||||
|
case "RETURNED":
|
||||||
|
case "DEFECTIVE":
|
||||||
|
case "WARRANTY_PENDING":
|
||||||
|
case "WARRANTY_SENT":
|
||||||
|
case "WARRANTY_REPLACED":
|
||||||
|
case "ASSIGNED":
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
String msg = "Invalid enrollment status type: " + status + ". \nValid status types " +
|
String msg = "Invalid enrollment status type: " + status + ". \nValid status types " +
|
||||||
"are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
|
"are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
|
||||||
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
|
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED | CONFIGURED | READY_TO_CONNECT | " +
|
||||||
|
"RETURN_PENDING | RETURNED | DEFECTIVE | WARRANTY_PENDING | WARRANTY_SENT | " +
|
||||||
|
"WARRANTY_REPLACED | ASSIGNED |";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -51,7 +51,7 @@
|
|||||||
<Bundle-Description>Entgra Logger Bundle</Bundle-Description>
|
<Bundle-Description>Entgra Logger Bundle</Bundle-Description>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
io.entgra.device.mgt.extensions.logger,
|
io.entgra.device.mgt.extensions.logger,
|
||||||
org.apache.commons.logging;version="[1.2,2)
|
org.apache.commons.logging
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
io.entgra.device.mgt.extensions.logger.*
|
io.entgra.device.mgt.extensions.logger.*
|
||||||
|
|||||||
@ -24,57 +24,29 @@ import org.apache.commons.logging.Log;
|
|||||||
|
|
||||||
public interface EntgraLogger extends Log {
|
public interface EntgraLogger extends Log {
|
||||||
|
|
||||||
void info(String message);
|
void info(Object object, LogContext logContext);
|
||||||
|
|
||||||
void info(String message, Throwable t);
|
void info(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void info(String message, LogContext logContext);
|
void debug(Object object, LogContext logContext);
|
||||||
|
|
||||||
void debug(String message);
|
void debug(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void debug(String message, Throwable t);
|
void error(Object object, LogContext logContext);
|
||||||
|
|
||||||
void debug(String message, LogContext logContext);
|
void error(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void error(String message);
|
void fatal(Object object, LogContext logContext);
|
||||||
|
|
||||||
void error(String message, Throwable t);
|
void fatal(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void error(String message, LogContext logContext);
|
void trace(Object object, LogContext logContext);
|
||||||
|
|
||||||
void error(String message, Throwable t, LogContext logContext);
|
void trace(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void warn(String message);
|
void warn(Object object, LogContext logContext);
|
||||||
|
|
||||||
void warn(String message, Throwable t);
|
void warn(Object object, Throwable t, LogContext logContext);
|
||||||
|
|
||||||
void warn(String message, LogContext logContext);
|
|
||||||
|
|
||||||
void warn(String message, Throwable t, LogContext logContext);
|
|
||||||
|
|
||||||
void trace(String message);
|
|
||||||
|
|
||||||
void trace(String message, Throwable t);
|
|
||||||
|
|
||||||
void trace(String message, LogContext logContext);
|
|
||||||
|
|
||||||
void fatal(String message);
|
|
||||||
|
|
||||||
void fatal(String message, Throwable t);
|
|
||||||
|
|
||||||
void fatal(String message, LogContext logContext);
|
|
||||||
|
|
||||||
boolean isDebugEnabled();
|
|
||||||
|
|
||||||
boolean isErrorEnabled();
|
|
||||||
|
|
||||||
boolean isFatalEnabled();
|
|
||||||
|
|
||||||
boolean isInfoEnabled();
|
|
||||||
|
|
||||||
boolean isTraceEnabled();
|
|
||||||
|
|
||||||
boolean isWarnEnabled();
|
|
||||||
|
|
||||||
void clearLogContext();
|
void clearLogContext();
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt-extensions</artifactId>
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -35,8 +35,11 @@ public class DeviceList extends BasePaginatedResult {
|
|||||||
@ApiModelProperty(name = "message", value = "Send information text to the billing UI", required = false)
|
@ApiModelProperty(name = "message", value = "Send information text to the billing UI", required = false)
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
@ApiModelProperty(name = "billedDateIsValid", value = "Check if user entered date is valid", required = false)
|
@ApiModelProperty(name = "deviceCount", value = "Total count of all devices per tenant", required = false)
|
||||||
private boolean billedDateIsValid;
|
private double deviceCount;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "billPeriod", value = "Billed period", required = false)
|
||||||
|
private String billPeriod;
|
||||||
|
|
||||||
@ApiModelProperty(value = "List of devices returned")
|
@ApiModelProperty(value = "List of devices returned")
|
||||||
@JsonProperty("devices")
|
@JsonProperty("devices")
|
||||||
@ -48,12 +51,20 @@ public class DeviceList extends BasePaginatedResult {
|
|||||||
this.devices = devices;
|
this.devices = devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBilledDateIsValid() {
|
public String getBillPeriod() {
|
||||||
return billedDateIsValid;
|
return billPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBilledDateIsValid(boolean billedDateIsValid) {
|
public void setBillPeriod(String billPeriod) {
|
||||||
this.billedDateIsValid = billedDateIsValid;
|
this.billPeriod = billPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDeviceCount() {
|
||||||
|
return deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceCount(double deviceCount) {
|
||||||
|
this.deviceCount = deviceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
|
|||||||
@ -344,179 +344,6 @@ public interface DeviceManagementService {
|
|||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limit);
|
int limit);
|
||||||
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/billing")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Getting Cost details of devices in a tenant",
|
|
||||||
notes = "Provides individual cost and total cost of all devices per tenant.",
|
|
||||||
tags = "Device Management",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
|
|
||||||
response = DeviceList.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 was last modified.\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.\n"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "The incoming request has more than one selection criteria defined via the query parameters.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "The search criteria did not match any device registered with the server.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@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 the device list.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getDevicesBilling(
|
|
||||||
@ApiParam(
|
|
||||||
name = "tenantDomain",
|
|
||||||
value = "The tenant domain.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("tenantDomain")
|
|
||||||
String tenantDomain,
|
|
||||||
@ApiParam(
|
|
||||||
name = "startDate",
|
|
||||||
value = "The start date.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("startDate")
|
|
||||||
Timestamp startDate,
|
|
||||||
@ApiParam(
|
|
||||||
name = "endDate",
|
|
||||||
value = "The end date.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("endDate")
|
|
||||||
Timestamp endDate,
|
|
||||||
@ApiParam(
|
|
||||||
name = "generateBill",
|
|
||||||
value = "The generate bill boolean.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("generateBill")
|
|
||||||
boolean generateBill,
|
|
||||||
@ApiParam(
|
|
||||||
name = "offset",
|
|
||||||
value = "The starting pagination index for the complete list of qualified items.",
|
|
||||||
required = false,
|
|
||||||
defaultValue = "0")
|
|
||||||
@QueryParam("offset")
|
|
||||||
int offset,
|
|
||||||
@ApiParam(
|
|
||||||
name = "limit",
|
|
||||||
value = "Provide how many device details you require from the starting pagination index/offset.",
|
|
||||||
required = false,
|
|
||||||
defaultValue = "10")
|
|
||||||
@QueryParam("limit")
|
|
||||||
int limit);
|
|
||||||
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/billing/file")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Getting Cost details of devices in a tenant",
|
|
||||||
notes = "Provides individual cost and total cost of all devices per tenant.",
|
|
||||||
tags = "Device Management",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
|
|
||||||
response = DeviceList.class,
|
|
||||||
responseHeaders = {
|
|
||||||
@ResponseHeader(
|
|
||||||
name = "Content-Type",
|
|
||||||
description = "The content type of the body"),
|
|
||||||
@ResponseHeader(
|
|
||||||
name = "Content-Disposition",
|
|
||||||
description = "The content disposition 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 was last modified.\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.\n"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "The incoming request has more than one selection criteria defined via the query parameters.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "The search criteria did not match any device registered with the server.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@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 the device list.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response exportBilling(
|
|
||||||
@ApiParam(
|
|
||||||
name = "tenantDomain",
|
|
||||||
value = "The tenant domain.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("tenantDomain")
|
|
||||||
String tenantDomain,
|
|
||||||
@ApiParam(
|
|
||||||
name = "startDate",
|
|
||||||
value = "The start date.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("startDate")
|
|
||||||
Timestamp startDate,
|
|
||||||
@ApiParam(
|
|
||||||
name = "endDate",
|
|
||||||
value = "The end date.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("endDate")
|
|
||||||
Timestamp endDate,
|
|
||||||
@ApiParam(
|
|
||||||
name = "generateBill",
|
|
||||||
value = "The generate bill boolean.",
|
|
||||||
required = false)
|
|
||||||
@QueryParam("generateBill")
|
|
||||||
boolean generateBill);
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
|
|||||||
@ -65,6 +65,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SwaggerDefinition(
|
@SwaggerDefinition(
|
||||||
@ -110,7 +111,14 @@ import java.util.List;
|
|||||||
key = "perm:devices:permanent-delete",
|
key = "perm:devices:permanent-delete",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/devices/permanent-delete"}
|
permissions = {"/device-mgt/admin/devices/permanent-delete"}
|
||||||
)
|
),
|
||||||
|
@Scope(
|
||||||
|
name = "Get Usage of Devices",
|
||||||
|
description = "Get Usage of Devices",
|
||||||
|
key = "perm:admin:usage:view",
|
||||||
|
roles = {"Internal/devicemgt-admin"},
|
||||||
|
permissions = {"/device-mgt/admin/devices/usage/view"}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public interface DeviceManagementAdminService {
|
public interface DeviceManagementAdminService {
|
||||||
@ -423,4 +431,78 @@ public interface DeviceManagementAdminService {
|
|||||||
List<String> actions
|
List<String> actions
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/billing")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "Getting Cost details of devices in a tenant",
|
||||||
|
notes = "Provides individual cost and total cost of all devices per tenant.",
|
||||||
|
tags = "Device Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:usage:view")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
|
||||||
|
response = DeviceList.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Disposition",
|
||||||
|
description = "The content disposition 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 was last modified.\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.\n"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message = "The incoming request has more than one selection criteria defined via the query parameters.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "The search criteria did not match any device registered with the server.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@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 the device list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response getBilling(
|
||||||
|
@ApiParam(
|
||||||
|
name = "tenantDomain",
|
||||||
|
value = "The tenant domain.",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("tenantDomain")
|
||||||
|
String tenantDomain,
|
||||||
|
@ApiParam(
|
||||||
|
name = "startDate",
|
||||||
|
value = "The start date.",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("startDate")
|
||||||
|
Timestamp startDate,
|
||||||
|
@ApiParam(
|
||||||
|
name = "endDate",
|
||||||
|
value = "The end date.",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("endDate")
|
||||||
|
Timestamp endDate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -355,105 +355,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
|
||||||
@Override
|
|
||||||
@Path("/billing")
|
|
||||||
public Response getDevicesBilling(
|
|
||||||
@QueryParam("tenantDomain") String tenantDomain,
|
|
||||||
@QueryParam("startDate") Timestamp startDate,
|
|
||||||
@QueryParam("endDate") Timestamp endDate,
|
|
||||||
@QueryParam("generateBill") boolean generateBill,
|
|
||||||
@QueryParam("offset") int offset,
|
|
||||||
@DefaultValue("10")
|
|
||||||
@QueryParam("limit") int limit) {
|
|
||||||
try {
|
|
||||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
||||||
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
PaginationRequest request = new PaginationRequest(offset, limit);
|
|
||||||
PaginationResult result;
|
|
||||||
DeviceList devices = new DeviceList();
|
|
||||||
int tenantId = 0;
|
|
||||||
RealmService realmService = DeviceMgtAPIUtils.getRealmService();
|
|
||||||
|
|
||||||
if (!tenantDomain.isEmpty()) {
|
|
||||||
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
|
|
||||||
} else {
|
|
||||||
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = dms.getAllDevicesBillings(request, tenantId, tenantDomain, startDate, endDate, generateBill);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
String msg = "Error occurred when trying to retrieve billing data";
|
|
||||||
log.error(msg, exception);
|
|
||||||
return Response.serverError().entity(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
int resultCount = result.getRecordsTotal();
|
|
||||||
if (resultCount == 0) {
|
|
||||||
Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
devices.setList((List<Device>) result.getData());
|
|
||||||
devices.setBilledDateIsValid(result.isBilledDateIsValid());
|
|
||||||
devices.setMessage(result.getMessage());
|
|
||||||
devices.setCount(result.getRecordsTotal());
|
|
||||||
devices.setTotalCost(result.getTotalCost());
|
|
||||||
return Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred while retrieving billing data";
|
|
||||||
log.error(msg, e);
|
|
||||||
return Response.serverError().entity(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Override
|
|
||||||
@Path("/billing/file")
|
|
||||||
public Response exportBilling(
|
|
||||||
@QueryParam("tenantDomain") String tenantDomain,
|
|
||||||
@QueryParam("startDate") Timestamp startDate,
|
|
||||||
@QueryParam("endDate") Timestamp endDate,
|
|
||||||
@QueryParam("generateBill") boolean generateBill) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
||||||
PaginationResult result;
|
|
||||||
int tenantId = 0;
|
|
||||||
RealmService realmService = DeviceMgtAPIUtils.getRealmService();
|
|
||||||
DeviceList devices = new DeviceList();
|
|
||||||
|
|
||||||
if (!tenantDomain.isEmpty()) {
|
|
||||||
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
|
|
||||||
} else {
|
|
||||||
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = dms.createBillingFile(tenantId, tenantDomain, startDate, endDate, generateBill);
|
|
||||||
|
|
||||||
} catch (Exception exception) {
|
|
||||||
String msg = "Error occurred when trying to retrieve billing data without pagination";
|
|
||||||
log.error(msg, exception);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
devices.setList((List<Device>) result.getData());
|
|
||||||
devices.setBilledDateIsValid(result.isBilledDateIsValid());
|
|
||||||
devices.setMessage(result.getMessage());
|
|
||||||
devices.setCount(result.getRecordsTotal());
|
|
||||||
devices.setTotalCost(result.getTotalCost());
|
|
||||||
return Response.status(Response.Status.OK).entity(devices).build();
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred while retrieving billing data without pagination";
|
|
||||||
log.error(msg, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
@Path("/user-devices")
|
@Path("/user-devices")
|
||||||
|
|||||||
@ -54,6 +54,7 @@ import org.wso2.carbon.registry.core.session.UserRegistry;
|
|||||||
import org.wso2.carbon.registry.resource.services.utils.ChangeRolePermissionsUtil;
|
import org.wso2.carbon.registry.resource.services.utils.ChangeRolePermissionsUtil;
|
||||||
import org.wso2.carbon.user.api.*;
|
import org.wso2.carbon.user.api.*;
|
||||||
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.constants.UserCoreErrorConstants.ErrorMessages;
|
||||||
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
||||||
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
||||||
@ -316,21 +317,31 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been"
|
entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been"
|
||||||
+ " added").build();
|
+ " added").build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
|
String errorCode = "";
|
||||||
|
String errorMessage = e.getMessage();
|
||||||
|
if (errorMessage != null && !errorMessage.isEmpty() &&
|
||||||
|
errorMessage.contains(ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode())) {
|
||||||
|
errorCode = e.getMessage().split("-")[0].trim();
|
||||||
|
}
|
||||||
|
if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) {
|
||||||
|
String roleName = roleInfo.getRoleName().split("/")[1];
|
||||||
|
String msg = "Role already exists with name " + roleName + ".";
|
||||||
|
log.warn(msg);
|
||||||
|
return Response.status(Response.Status.CONFLICT).entity(msg).build();
|
||||||
|
} else {
|
||||||
String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'";
|
String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
String msg = "Error occurred while composing the URI at which the information of the newly created role " +
|
String msg = "Error occurred while composing the URI at which the information of the newly created role " +
|
||||||
"can be retrieved";
|
"can be retrieved";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
String msg = "Error occurred while encoding role name";
|
String msg = "Error occurred while encoding role name";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,12 +52,15 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@ -71,6 +74,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/admin/devices")
|
@Path("/admin/devices")
|
||||||
@ -147,7 +151,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
@Path("/device-owner")
|
@Path("/device-owner")
|
||||||
public Response updateEnrollOwner(
|
public Response updateEnrollOwner(
|
||||||
@QueryParam("owner") String owner,
|
@QueryParam("owner") String owner,
|
||||||
List<String> deviceIdentifiers){
|
List<String> deviceIdentifiers) {
|
||||||
try {
|
try {
|
||||||
if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, true, deviceIdentifiers)) {
|
if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, true, deviceIdentifiers)) {
|
||||||
String msg = "Device owner is updated successfully.";
|
String msg = "Device owner is updated successfully.";
|
||||||
@ -190,8 +194,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
} catch (InvalidDeviceException e) {
|
||||||
catch (InvalidDeviceException e) {
|
|
||||||
String msg = "Found Invalid devices";
|
String msg = "Found Invalid devices";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||||
@ -205,7 +208,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
public Response triggerCorrectiveActions(
|
public Response triggerCorrectiveActions(
|
||||||
@PathParam("deviceId") String deviceIdentifier,
|
@PathParam("deviceId") String deviceIdentifier,
|
||||||
@PathParam("featureCode") String featureCode,
|
@PathParam("featureCode") String featureCode,
|
||||||
List<String> actions){
|
List<String> actions) {
|
||||||
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
|
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
PlatformConfigurationManagementService platformConfigurationManagementService = DeviceMgtAPIUtils
|
PlatformConfigurationManagementService platformConfigurationManagementService = DeviceMgtAPIUtils
|
||||||
.getPlatformConfigurationManagementService();
|
.getPlatformConfigurationManagementService();
|
||||||
@ -233,4 +236,51 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK).entity("Triggered action successfully").build();
|
return Response.status(Response.Status.OK).entity("Triggered action successfully").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Override
|
||||||
|
@Path("/billing")
|
||||||
|
public Response getBilling(
|
||||||
|
@QueryParam("tenantDomain") String tenantDomain,
|
||||||
|
@QueryParam("startDate") Timestamp startDate,
|
||||||
|
@QueryParam("endDate") Timestamp endDate) {
|
||||||
|
try {
|
||||||
|
PaginationResult result;
|
||||||
|
int tenantId = 0;
|
||||||
|
RealmService realmService = DeviceMgtAPIUtils.getRealmService();
|
||||||
|
|
||||||
|
int tenantIdContext = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
if (!tenantDomain.isEmpty()) {
|
||||||
|
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
|
||||||
|
}
|
||||||
|
if (tenantIdContext != MultitenantConstants.SUPER_TENANT_ID && tenantIdContext != tenantId) {
|
||||||
|
String msg = "Current logged in user is not authorized to access billing details of other tenants";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
|
||||||
|
} else {
|
||||||
|
DeviceList devices = new DeviceList();
|
||||||
|
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
|
result = dms.createBillingFile(tenantId, tenantDomain, startDate, endDate);
|
||||||
|
devices.setList((List<Device>) result.getData());
|
||||||
|
devices.setDeviceCount(result.getTotalDeviceCount());
|
||||||
|
devices.setMessage(result.getMessage());
|
||||||
|
devices.setTotalCost(result.getTotalCost());
|
||||||
|
devices.setBillPeriod(startDate.toString() + " - " + endDate.toString());
|
||||||
|
return Response.status(Response.Status.OK).entity(devices).build();
|
||||||
|
}
|
||||||
|
} catch (BadRequestException e) {
|
||||||
|
String msg = "Bad request, can't proceed. Hence verify the request and re-try";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving billing data";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "Error occurred while processing tenant configuration.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,11 +153,21 @@ public class RequestValidationUtil {
|
|||||||
case "REMOVED":
|
case "REMOVED":
|
||||||
case "BLOCKED":
|
case "BLOCKED":
|
||||||
case "CREATED":
|
case "CREATED":
|
||||||
|
case "CONFIGURED":
|
||||||
|
case "READY_TO_CONNECT":
|
||||||
|
case "RETURN_PENDING":
|
||||||
|
case "RETURNED":
|
||||||
|
case "DEFECTIVE":
|
||||||
|
case "WARRANTY_PENDING":
|
||||||
|
case "WARRANTY_SENT":
|
||||||
|
case "WARRANTY_REPLACED":
|
||||||
|
case "ASSIGNED":
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
String msg = "Invalid enrollment status type: " + status + ". \nValid status types are " +
|
String msg = "Invalid enrollment status type: " + status + ". \nValid status types are " +
|
||||||
"ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
|
"ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
|
||||||
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
|
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED | CONFIGURED | READY_TO_CONNECT | " +
|
||||||
|
"RETURN_PENDING | RETURNED | DEFECTIVE | WARRANTY_PENDING | WARRANTY_SENT | WARRANTY_REPLACED | ASSIGNED ";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder()
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder()
|
||||||
.setCode(HttpStatus.SC_BAD_REQUEST)
|
.setCode(HttpStatus.SC_BAD_REQUEST)
|
||||||
@ -175,12 +185,18 @@ public class RequestValidationUtil {
|
|||||||
switch (ownership) {
|
switch (ownership) {
|
||||||
case "BYOD":
|
case "BYOD":
|
||||||
case "COPE":
|
case "COPE":
|
||||||
|
case "WORK_PROFILE":
|
||||||
|
case "GOOGLE_ENTERPRISE":
|
||||||
|
case "COSU":
|
||||||
|
case "FULLY_MANAGED":
|
||||||
|
case "DEDICATED_DEVICE":
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
throw new InputValidationException(
|
throw new InputValidationException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
||||||
"Invalid ownership type received. " +
|
"Invalid ownership type received. " +
|
||||||
"Valid ownership types are BYOD | COPE").build());
|
"Valid ownership types are BYOD | COPE " +
|
||||||
|
"WORK_PROFILE | GOOGLE_ENTERPRISE | COSU | FULLY_MANAGED | DEDICATED_DEVICE").build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel(value = "BillingResponse", description = "This class carries all information related to a billing response.")
|
||||||
|
public class BillingResponse implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "year", value = "Year of the billed period",
|
||||||
|
required = false)
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "totalCostPerYear", value = "Bill for a period of year", required = false)
|
||||||
|
private double totalCostPerYear;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "devices", value = "Billed list of devices per year", required = false)
|
||||||
|
private List<Device> device;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "billPeriod", value = "Billed period", required = false)
|
||||||
|
private String billPeriod;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "startDate", value = "Start Date of period", required = false)
|
||||||
|
private String startDate;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "endDate", value = "End Date of period", required = false)
|
||||||
|
private String endDate;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "deviceCount", value = "Device count for a billing period",
|
||||||
|
required = false)
|
||||||
|
private int deviceCount;
|
||||||
|
|
||||||
|
public BillingResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BillingResponse(String year, double totalCostPerYear, List<Device> device, String billPeriod, String startDate, String endDate, int deviceCount) {
|
||||||
|
this.year = year;
|
||||||
|
this.totalCostPerYear = totalCostPerYear;
|
||||||
|
this.device = device;
|
||||||
|
this.billPeriod = billPeriod;
|
||||||
|
this.startDate = startDate;
|
||||||
|
this.endDate = endDate;
|
||||||
|
this.deviceCount = deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(String startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndDate() {
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(String endDate) {
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTotalCostPerYear() {
|
||||||
|
return totalCostPerYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalCostPerYear(double totalCostPerYear) {
|
||||||
|
this.totalCostPerYear = totalCostPerYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(String year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device> getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(List<Device> device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillPeriod() {
|
||||||
|
return billPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillPeriod(String billPeriod) {
|
||||||
|
this.billPeriod = billPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceCount() {
|
||||||
|
return deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceCount(int deviceCount) {
|
||||||
|
this.deviceCount = deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -47,18 +47,29 @@ public class PaginationResult implements Serializable {
|
|||||||
@ApiModelProperty(name = "totalCost", value = "Total cost of all devices per tenant", required = false)
|
@ApiModelProperty(name = "totalCost", value = "Total cost of all devices per tenant", required = false)
|
||||||
private double totalCost;
|
private double totalCost;
|
||||||
|
|
||||||
@ApiModelProperty(name = "billedDateIsValid", value = "Check if user entered date is valid", required = false)
|
@ApiModelProperty(name = "totalDeviceCount", value = "Total count of all devices per tenant", required = false)
|
||||||
private boolean billedDateIsValid;
|
private double totalDeviceCount;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "billPeriod", value = "Billed period", required = false)
|
||||||
|
private String billPeriod;
|
||||||
|
|
||||||
@ApiModelProperty(name = "message", value = "Send information text to the billing UI", required = false)
|
@ApiModelProperty(name = "message", value = "Send information text to the billing UI", required = false)
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public boolean isBilledDateIsValid() {
|
public String getBillPeriod() {
|
||||||
return billedDateIsValid;
|
return billPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBilledDateIsValid(boolean billedDateIsValid) {
|
public void setBillPeriod(String billPeriod) {
|
||||||
this.billedDateIsValid = billedDateIsValid;
|
this.billPeriod = billPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTotalDeviceCount() {
|
||||||
|
return totalDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalDeviceCount(double totalDeviceCount) {
|
||||||
|
this.totalDeviceCount = totalDeviceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (c) 2023, 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 org.wso2.carbon.device.mgt.common.otp.mgt.wrapper;
|
||||||
|
|
||||||
|
public class DownloadURLDetails {
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
private String URL;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public String getURL() {
|
||||||
|
return URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setURL(String URL) {
|
||||||
|
this.URL = URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation;
|
import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation;
|
||||||
import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
|
import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
|
||||||
|
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails;
|
||||||
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper;
|
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -34,7 +35,7 @@ public interface OTPManagementService {
|
|||||||
* @throws OTPManagementException if error occurs while creating OTP token and storing tenant details.
|
* @throws OTPManagementException if error occurs while creating OTP token and storing tenant details.
|
||||||
* @throws BadRequestException if found and incompatible payload to create OTP token.
|
* @throws BadRequestException if found and incompatible payload to create OTP token.
|
||||||
*/
|
*/
|
||||||
void sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException;
|
String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the validity of the OTP
|
* Check the validity of the OTP
|
||||||
@ -62,4 +63,13 @@ public interface OTPManagementService {
|
|||||||
*/
|
*/
|
||||||
void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation)
|
void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation)
|
||||||
throws OTPManagementException;
|
throws OTPManagementException;
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Send an e-mail to the requesting e-mail address with a product download URL
|
||||||
|
* @param downloadURLDetails Contains the details to send product download e-mail
|
||||||
|
* @throws OTPManagementException if request payload doesn't contains required details to send the product
|
||||||
|
* download mail.
|
||||||
|
*/
|
||||||
|
void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@ public final class DeviceManagementConstants {
|
|||||||
public static final String DEVICE_CACHE = "DEVICE_CACHE";
|
public static final String DEVICE_CACHE = "DEVICE_CACHE";
|
||||||
public static final String API_RESOURCE_PERMISSION_CACHE = "API_RESOURCE_CACHE_CACHE";
|
public static final String API_RESOURCE_PERMISSION_CACHE = "API_RESOURCE_CACHE_CACHE";
|
||||||
public static final String GEOFENCE_CACHE = "GEOFENCE_CACHE";
|
public static final String GEOFENCE_CACHE = "GEOFENCE_CACHE";
|
||||||
|
public static final String BILLING_CACHE = "BILLING_CACHE";
|
||||||
public static final String META_KEY = "PER_DEVICE_COST";
|
public static final String META_KEY = "PER_DEVICE_COST";
|
||||||
public static final String ACTIVE_STATUS = "ACTIVE";
|
public static final String ACTIVE_STATUS = "ACTIVE";
|
||||||
public static final String ENROLLMENT_NOTIFICATION_API_ENDPOINT = "/api/device-mgt/enrollment-notification";
|
public static final String ENROLLMENT_NOTIFICATION_API_ENDPOINT = "/api/device-mgt/enrollment-notification";
|
||||||
@ -131,6 +132,7 @@ public final class DeviceManagementConstants {
|
|||||||
public static final String USER_REGISTRATION_TEMPLATE = "user-registration";
|
public static final String USER_REGISTRATION_TEMPLATE = "user-registration";
|
||||||
public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment";
|
public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment";
|
||||||
public static final String USER_VERIFY_TEMPLATE = "user-verify";
|
public static final String USER_VERIFY_TEMPLATE = "user-verify";
|
||||||
|
public static final String PRODUCT_DOWNLOAD_LINK_SHARING_TEMPLATE = "share-product-download-url";
|
||||||
public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier";
|
public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier";
|
||||||
public static final String USER_WELCOME_TEMPLATE = "user-welcome";
|
public static final String USER_WELCOME_TEMPLATE = "user-welcome";
|
||||||
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
|
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
|
||||||
|
|||||||
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.cache;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class BillingCacheKey {
|
||||||
|
|
||||||
|
private String tenantDomain;
|
||||||
|
private Timestamp startDate;
|
||||||
|
private Timestamp endDate;
|
||||||
|
private volatile int hashCode;
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(Timestamp startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getEndDate() {
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(Timestamp endDate) {
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!BillingCacheKey.class.isAssignableFrom(obj.getClass())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final BillingCacheKey other = (BillingCacheKey) obj;
|
||||||
|
String thisId = this.tenantDomain + "_" + this.startDate + "_" + this.endDate;
|
||||||
|
String otherId = other.tenantDomain + "_" + other.startDate + "_" + this.endDate;
|
||||||
|
if (!thisId.equals(otherId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
if (hashCode == 0) {
|
||||||
|
hashCode = Objects.hash(tenantDomain, startDate, endDate);
|
||||||
|
}
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.cache;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface BillingCacheManager {
|
||||||
|
/**
|
||||||
|
* Adds a given billing object to the billing-cache.
|
||||||
|
* @param startDate - startDate of the billing period.
|
||||||
|
* @param endDate - endDate of the billing period.
|
||||||
|
* @param paginationResult - PaginationResult object to be added.
|
||||||
|
* @param tenantDomain - Owning tenant of the billing.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void addBillingToCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a billing object from billing-cache.
|
||||||
|
* @param startDate - startDate of the billing period.
|
||||||
|
* @param endDate - endDate of the billing period.
|
||||||
|
* @param tenantDomain - Owning tenant of the billing.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void removeBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a list of devices from billing-cache.
|
||||||
|
* @param billingList - List of Cache-Keys of the billing objects to be removed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void removeBillingsFromCache(List<BillingCacheKey> billingList) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a given billing object in the billing-cache.
|
||||||
|
* @param startDate - startDate of the billing period.
|
||||||
|
* @param endDate - endDate of the billing period.
|
||||||
|
* @param paginationResult - PaginationResult object to be updated.
|
||||||
|
* @param tenantDomain - Owning tenant of the billing.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void updateBillingInCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches a billing object from billing-cache.
|
||||||
|
* @param startDate - startDate of the billing period.
|
||||||
|
* @param endDate - endDate of the billing period.
|
||||||
|
* @param tenantDomain - Owning tenant of the billing.
|
||||||
|
* @return Device object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
PaginationResult getBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate);
|
||||||
|
}
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.cache.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.BillingCacheKey;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.BillingCacheManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
|
import javax.cache.Cache;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of BillingCacheManager.
|
||||||
|
*/
|
||||||
|
public class BillingCacheManagerImpl implements BillingCacheManager {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(BillingCacheManagerImpl.class);
|
||||||
|
|
||||||
|
private static BillingCacheManagerImpl billingCacheManager;
|
||||||
|
|
||||||
|
private BillingCacheManagerImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BillingCacheManagerImpl getInstance() {
|
||||||
|
if (billingCacheManager == null) {
|
||||||
|
synchronized (BillingCacheManagerImpl.class) {
|
||||||
|
if (billingCacheManager == null) {
|
||||||
|
billingCacheManager = new BillingCacheManagerImpl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return billingCacheManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBillingToCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||||
|
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||||
|
if (lCache != null) {
|
||||||
|
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||||
|
if (lCache.containsKey(cacheKey)) {
|
||||||
|
this.updateBillingInCache(paginationResult, tenantDomain, startDate, endDate);
|
||||||
|
} else {
|
||||||
|
lCache.put(cacheKey, paginationResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||||
|
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||||
|
if (lCache != null) {
|
||||||
|
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||||
|
if (lCache.containsKey(cacheKey)) {
|
||||||
|
lCache.remove(cacheKey);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String msg = "Failed to remove selected billing from cache";
|
||||||
|
log.error(msg);
|
||||||
|
throw new DeviceManagementException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeBillingsFromCache(List<BillingCacheKey> billingList) throws DeviceManagementException {
|
||||||
|
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||||
|
if (lCache != null) {
|
||||||
|
for (BillingCacheKey cacheKey : billingList) {
|
||||||
|
if (lCache.containsKey(cacheKey)) {
|
||||||
|
lCache.remove(cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String msg = "Failed to remove billing from cache";
|
||||||
|
log.error(msg);
|
||||||
|
throw new DeviceManagementException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBillingInCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||||
|
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||||
|
if (lCache != null) {
|
||||||
|
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||||
|
if (lCache.containsKey(cacheKey)) {
|
||||||
|
lCache.replace(cacheKey, paginationResult);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String msg = "Failed to update billing cache";
|
||||||
|
log.error(msg);
|
||||||
|
throw new DeviceManagementException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO remove null check from here and do cache enable check in the methods calling this
|
||||||
|
@Override
|
||||||
|
public PaginationResult getBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) {
|
||||||
|
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||||
|
if (lCache != null) {
|
||||||
|
return lCache.get(getCacheKey(tenantDomain, startDate, endDate));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method generates the billing CacheKey and returns it.
|
||||||
|
*/
|
||||||
|
private BillingCacheKey getCacheKey(String tenantDomain, Timestamp startDate, Timestamp endDate) {
|
||||||
|
BillingCacheKey billingCacheKey = new BillingCacheKey();
|
||||||
|
billingCacheKey.setTenantDomain(tenantDomain);
|
||||||
|
billingCacheKey.setStartDate(startDate);
|
||||||
|
billingCacheKey.setEndDate(endDate);
|
||||||
|
return billingCacheKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,6 +21,7 @@ import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotif
|
|||||||
import org.wso2.carbon.device.mgt.common.roles.config.DefaultRoles;
|
import org.wso2.carbon.device.mgt.common.roles.config.DefaultRoles;
|
||||||
import org.wso2.carbon.device.mgt.core.config.analytics.OperationAnalyticsConfiguration;
|
import org.wso2.carbon.device.mgt.core.config.analytics.OperationAnalyticsConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.config.archival.ArchivalConfiguration;
|
import org.wso2.carbon.device.mgt.core.config.archival.ArchivalConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.cache.BillingCacheConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration;
|
import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
|
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.config.cache.GeoFenceCacheConfiguration;
|
import org.wso2.carbon.device.mgt.core.config.cache.GeoFenceCacheConfiguration;
|
||||||
@ -58,6 +59,7 @@ public final class DeviceManagementConfig {
|
|||||||
private DeviceStatusTaskConfig deviceStatusTaskConfig;
|
private DeviceStatusTaskConfig deviceStatusTaskConfig;
|
||||||
private DeviceCacheConfiguration deviceCacheConfiguration;
|
private DeviceCacheConfiguration deviceCacheConfiguration;
|
||||||
private GeoFenceCacheConfiguration geoFenceCacheConfiguration;
|
private GeoFenceCacheConfiguration geoFenceCacheConfiguration;
|
||||||
|
private BillingCacheConfiguration billingCacheConfiguration;
|
||||||
private EventOperationTaskConfiguration eventOperationTaskConfiguration;
|
private EventOperationTaskConfiguration eventOperationTaskConfiguration;
|
||||||
private CertificateCacheConfiguration certificateCacheConfiguration;
|
private CertificateCacheConfiguration certificateCacheConfiguration;
|
||||||
private OperationAnalyticsConfiguration operationAnalyticsConfiguration;
|
private OperationAnalyticsConfiguration operationAnalyticsConfiguration;
|
||||||
@ -169,6 +171,15 @@ public final class DeviceManagementConfig {
|
|||||||
this.geoFenceCacheConfiguration = geoFenceCacheConfiguration;
|
this.geoFenceCacheConfiguration = geoFenceCacheConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "BillingCacheConfiguration", required = true)
|
||||||
|
public BillingCacheConfiguration getBillingCacheConfiguration() {
|
||||||
|
return billingCacheConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingCacheConfiguration(BillingCacheConfiguration billingCacheConfiguration) {
|
||||||
|
this.billingCacheConfiguration = billingCacheConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlElement(name = "EventOperationTaskConfiguration", required = true)
|
@XmlElement(name = "EventOperationTaskConfiguration", required = true)
|
||||||
public EventOperationTaskConfiguration getEventOperationTaskConfiguration() {
|
public EventOperationTaskConfiguration getEventOperationTaskConfiguration() {
|
||||||
return eventOperationTaskConfiguration;
|
return eventOperationTaskConfiguration;
|
||||||
|
|||||||
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.cache;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement(name = "BillingCacheConfiguration")
|
||||||
|
public class BillingCacheConfiguration {
|
||||||
|
private boolean isEnabled;
|
||||||
|
private int expiryTime;
|
||||||
|
private long capacity;
|
||||||
|
|
||||||
|
@XmlElement(name = "Enable", required = true)
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
isEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "ExpiryTime", required = true)
|
||||||
|
public int getExpiryTime() {
|
||||||
|
return expiryTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpiryTime(int expiryTime) {
|
||||||
|
this.expiryTime = expiryTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Capacity", required = true)
|
||||||
|
public long getCapacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapacity(long capacity) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Billing;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface BillingDAO {
|
|
||||||
|
|
||||||
void addBilling(int deviceId, int tenantId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
List<Billing> getBilling(int deviceId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException;
|
|
||||||
}
|
|
||||||
@ -293,6 +293,50 @@ public interface DeviceDAO {
|
|||||||
*/
|
*/
|
||||||
List<Device> getDevices(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
List<Device> getDevices(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the not removed device list in a year of a given tenant without pagination.
|
||||||
|
*
|
||||||
|
* @param tenantId tenant id.
|
||||||
|
* @param startDate start date of usage period.
|
||||||
|
* @param endDate end date of usage period.
|
||||||
|
* @return returns a list of not removed devices enrolled in that year.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getNonRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the removed device list in a year of a given tenant without pagination.
|
||||||
|
*
|
||||||
|
* @param tenantId tenant id.
|
||||||
|
* @param startDate start date of usage period.
|
||||||
|
* @param endDate end date of usage period.
|
||||||
|
* @return returns a list of removed devices enrolled in that year.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the not removed device list in the prior year of a given tenant without pagination.
|
||||||
|
*
|
||||||
|
* @param tenantId tenant id.
|
||||||
|
* @param startDate start date of usage period.
|
||||||
|
* @param endDate end date of usage period.
|
||||||
|
* @return returns a list of not removed devices enrolled prior to that year.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getNonRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to retrieve the removed device list in the prior year of a given tenant without pagination.
|
||||||
|
*
|
||||||
|
* @param tenantId tenant id.
|
||||||
|
* @param startDate start date of usage period.
|
||||||
|
* @param endDate end date of usage period.
|
||||||
|
* @return returns a list of removed devices enrolled prior to that year.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to retrieve the devices of a given tenant without pagination.
|
* This method is used to retrieve the devices of a given tenant without pagination.
|
||||||
* @param tenantId tenant id.
|
* @param tenantId tenant id.
|
||||||
|
|||||||
@ -125,11 +125,6 @@ public class DeviceManagementDAOFactory {
|
|||||||
return new EnrollmentDAOImpl();
|
return new EnrollmentDAOImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BillingDAO getBillingDAO() {
|
|
||||||
return new BillingDAOImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static TrackerDAO getTrackerDAO() {
|
public static TrackerDAO getTrackerDAO() {
|
||||||
if (databaseEngine != null) {
|
if (databaseEngine != null) {
|
||||||
switch (databaseEngine) {
|
switch (databaseEngine) {
|
||||||
|
|||||||
@ -33,8 +33,6 @@ public interface EnrollmentDAO {
|
|||||||
|
|
||||||
boolean updateEnrollmentStatus(List<EnrolmentInfo> enrolmentInfos) throws DeviceManagementDAOException;
|
boolean updateEnrollmentStatus(List<EnrolmentInfo> enrolmentInfos) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
boolean updateEnrollmentLastBilledDate(EnrolmentInfo enrolmentInfos, Timestamp lastBilledDate, int tenantId) throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
int removeEnrollment(int deviceId, String currentOwner, int tenantId) throws DeviceManagementDAOException;
|
int removeEnrollment(int deviceId, String currentOwner, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
@ -1,71 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Billing;
|
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.BillingDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BillingDAOImpl implements BillingDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addBilling(int deviceId, int tenantId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException {
|
|
||||||
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "INSERT INTO DM_BILLING(DEVICE_ID, TENANT_ID, BILLING_START, BILLING_END) VALUES(?, ?, ?, ?)";
|
|
||||||
stmt = conn.prepareStatement(sql, new String[] {"invoice_id"});
|
|
||||||
stmt.setInt(1, deviceId);
|
|
||||||
stmt.setInt(2,tenantId);
|
|
||||||
stmt.setTimestamp(3, billingStart);
|
|
||||||
stmt.setTimestamp(4, billingEnd);
|
|
||||||
stmt.execute();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while adding billing period", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Billing> getBilling(int deviceId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException {
|
|
||||||
List<Billing> billings = new ArrayList<>();
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
EnrolmentInfo.Status status = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql;
|
|
||||||
|
|
||||||
sql = "SELECT * FROM DM_BILLING WHERE DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, deviceId);
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
Billing bill = new Billing(rs.getInt("INVOICE_ID"), rs.getInt("DEVICE_ID"),rs.getInt("TENANT_ID"),
|
|
||||||
(rs.getTimestamp("BILLING_START").getTime()), (rs.getTimestamp("BILLING_END").getTime()));
|
|
||||||
billings.add(bill);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred getting billing periods", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return billings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException {
|
|
||||||
return DeviceManagementDAOFactory.getConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -25,13 +25,7 @@ public class DeviceStatusDAOImpl implements DeviceStatusDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
// either we list all status values for the device using the device id or only get status values for the given enrolment id
|
// either we list all status values for the device using the device id or only get status values for the given enrolment id
|
||||||
String idType = isDeviceId ? "DEVICE_ID" : "ENROLMENT_ID";
|
String idType = isDeviceId ? "DEVICE_ID" : "ENROLMENT_ID";
|
||||||
String sql;
|
String sql = "SELECT ENROLMENT_ID, DEVICE_ID, UPDATE_TIME, STATUS, CHANGED_BY FROM DM_DEVICE_STATUS WHERE " + idType + " = ?";
|
||||||
|
|
||||||
if (billingStatus) {
|
|
||||||
sql = "SELECT ENROLMENT_ID, DEVICE_ID, UPDATE_TIME, STATUS, CHANGED_BY FROM DM_DEVICE_STATUS WHERE STATUS IN ('ACTIVE','REMOVED') AND " + idType + " = ?";
|
|
||||||
} else {
|
|
||||||
sql = "SELECT ENROLMENT_ID, DEVICE_ID, UPDATE_TIME, STATUS, CHANGED_BY FROM DM_DEVICE_STATUS WHERE " + idType + " = ?";
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter the data based on a date range if specified
|
// filter the data based on a date range if specified
|
||||||
if (fromDate != null){
|
if (fromDate != null){
|
||||||
@ -41,6 +35,10 @@ public class DeviceStatusDAOImpl implements DeviceStatusDAO {
|
|||||||
sql += " AND UPDATE_TIME <= ?";
|
sql += " AND UPDATE_TIME <= ?";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (billingStatus) {
|
||||||
|
sql += " ORDER BY UPDATE_TIME DESC";
|
||||||
|
}
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|||||||
@ -144,28 +144,6 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateEnrollmentLastBilledDate(EnrolmentInfo enrolmentInfo, Timestamp lastBilledDate, int tenantId) throws DeviceManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "UPDATE DM_ENROLMENT SET LAST_BILLED_DATE = ? WHERE ID = ? AND TENANT_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setLong(1, lastBilledDate.getTime());
|
|
||||||
stmt.setInt(2, enrolmentInfo.getId());
|
|
||||||
stmt.setInt(3, tenantId);
|
|
||||||
stmt.executeUpdate();
|
|
||||||
return true;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while updating enrolment last billed date.", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int removeEnrollment(int deviceId, String currentOwner,
|
public int removeEnrollment(int deviceId, String currentOwner,
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
int tenantId) throws DeviceManagementDAOException {
|
||||||
|
|||||||
@ -84,7 +84,6 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.IS_TRANSFERRED, " +
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.LAST_BILLED_DATE, " +
|
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
"FROM DM_ENROLMENT e, " +
|
"FROM DM_ENROLMENT e, " +
|
||||||
"(SELECT d.ID, " +
|
"(SELECT d.ID, " +
|
||||||
@ -188,6 +187,169 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = getConnection();
|
||||||
|
String sql = "SELECT d.ID AS DEVICE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, " +
|
||||||
|
"DESCRIPTION, " +
|
||||||
|
"NAME, " +
|
||||||
|
"DATE_OF_ENROLMENT, " +
|
||||||
|
"STATUS, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, " +
|
||||||
|
"TIMESTAMPDIFF(DAY, ?, DATE_OF_ENROLMENT) as DAYS_SINCE_ENROLLED " +
|
||||||
|
"FROM DM_DEVICE d, DM_ENROLMENT e " +
|
||||||
|
"WHERE " +
|
||||||
|
"e.TENANT_ID=? AND " +
|
||||||
|
"d.ID=e.DEVICE_ID AND " +
|
||||||
|
"STATUS !='REMOVED' AND " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_ENROLMENT BETWEEN ? AND ? " +
|
||||||
|
")";
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setString(1, String.valueOf(endDate));
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setString(3, String.valueOf(startDate));
|
||||||
|
stmt.setString(4, String.valueOf(endDate));
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
devices.add(DeviceManagementDAOUtil.loadDeviceBilling(rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of NonRemovedYearly device billing ", e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
Connection conn;
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "select d.ID AS DEVICE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, " +
|
||||||
|
"DESCRIPTION, " +
|
||||||
|
"NAME, " +
|
||||||
|
"DATE_OF_ENROLMENT, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, " +
|
||||||
|
"STATUS, " +
|
||||||
|
"TIMESTAMPDIFF(DAY, DATE_OF_LAST_UPDATE, DATE_OF_ENROLMENT) AS DAYS_USED " +
|
||||||
|
"from DM_DEVICE d, DM_ENROLMENT e " +
|
||||||
|
"where " +
|
||||||
|
"e.TENANT_ID=? and d.ID=e.DEVICE_ID and " +
|
||||||
|
"STATUS ='REMOVED' and " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_ENROLMENT between ? and ? " +
|
||||||
|
") and " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_LAST_UPDATE >= ? " +
|
||||||
|
")";
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.setString(2, String.valueOf(startDate));
|
||||||
|
stmt.setString(3, String.valueOf(endDate));
|
||||||
|
stmt.setString(4, String.valueOf(startDate));
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
devices.add(DeviceManagementDAOUtil.loadDeviceBilling(rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of RemovedYearly device billing ", e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
Connection conn;
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "select d.ID AS DEVICE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, " +
|
||||||
|
"DESCRIPTION, " +
|
||||||
|
"NAME, " +
|
||||||
|
"DATE_OF_ENROLMENT, " +
|
||||||
|
"STATUS, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, " +
|
||||||
|
"TIMESTAMPDIFF(DAY, ?, ?) as DAYS_SINCE_ENROLLED " +
|
||||||
|
"from DM_DEVICE d, DM_ENROLMENT e " +
|
||||||
|
"where " +
|
||||||
|
"e.TENANT_ID=? and " +
|
||||||
|
"d.ID=e.DEVICE_ID and " +
|
||||||
|
"STATUS !='REMOVED' and " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_ENROLMENT < ? " +
|
||||||
|
")";
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setString(1, String.valueOf(endDate));
|
||||||
|
stmt.setString(2, String.valueOf(startDate));
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setString(4, String.valueOf(startDate));
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
devices.add(DeviceManagementDAOUtil.loadDeviceBilling(rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of NonRemovedPriorYears device billing ", e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
Connection conn;
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "select d.ID AS DEVICE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, " +
|
||||||
|
"DESCRIPTION, " +
|
||||||
|
"NAME, " +
|
||||||
|
"DATE_OF_ENROLMENT, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, " +
|
||||||
|
"STATUS, " +
|
||||||
|
"TIMESTAMPDIFF(DAY, DATE_OF_LAST_UPDATE, ?) AS DAYS_USED " +
|
||||||
|
"from DM_DEVICE d, DM_ENROLMENT e " +
|
||||||
|
"where " +
|
||||||
|
"e.TENANT_ID=? and d.ID=e.DEVICE_ID and " +
|
||||||
|
"STATUS ='REMOVED' and " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_ENROLMENT < ? " +
|
||||||
|
") and " +
|
||||||
|
"(" +
|
||||||
|
"DATE_OF_LAST_UPDATE >= ? " +
|
||||||
|
")";
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setString(1, String.valueOf(startDate));
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setString(3, String.valueOf(startDate));
|
||||||
|
stmt.setString(4, String.valueOf(startDate));
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
devices.add(DeviceManagementDAOUtil.loadDeviceBilling(rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of RemovedPriorYears device billing ", e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
//Return only not removed id list
|
//Return only not removed id list
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDeviceListWithoutPagination(int tenantId)
|
public List<Device> getDeviceListWithoutPagination(int tenantId)
|
||||||
@ -197,10 +359,26 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT DM_DEVICE.ID AS DEVICE_ID, DEVICE_IDENTIFICATION, DESCRIPTION, DM_DEVICE.NAME AS DEVICE_NAME, DM_DEVICE_TYPE.NAME AS DEVICE_TYPE,\n" +
|
String sql = "SELECT " +
|
||||||
"DM_ENROLMENT.ID AS ENROLMENT_ID, DATE_OF_ENROLMENT,OWNER, OWNERSHIP,IS_TRANSFERRED, STATUS, DATE_OF_LAST_UPDATE, LAST_BILLED_DATE,\n" +
|
"DM_DEVICE.ID AS DEVICE_ID, " +
|
||||||
"TIMESTAMPDIFF(DAY, DATE_OF_ENROLMENT, CURDATE()) as DAYS_SINCE_ENROLLED FROM DM_DEVICE JOIN DM_ENROLMENT\n" +
|
"DEVICE_IDENTIFICATION, " +
|
||||||
"ON (DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) JOIN DM_DEVICE_TYPE ON (DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID) WHERE DM_ENROLMENT.TENANT_ID=?";
|
"DESCRIPTION, " +
|
||||||
|
"DM_DEVICE.NAME AS DEVICE_NAME, " +
|
||||||
|
"DM_DEVICE_TYPE.NAME AS DEVICE_TYPE, " +
|
||||||
|
"DM_ENROLMENT.ID AS ENROLMENT_ID, " +
|
||||||
|
"DATE_OF_ENROLMENT, " +
|
||||||
|
"OWNER, " +
|
||||||
|
"OWNERSHIP, " +
|
||||||
|
"IS_TRANSFERRED, " +
|
||||||
|
"STATUS, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, " +
|
||||||
|
"TIMESTAMPDIFF(DAY, DATE_OF_ENROLMENT, CURDATE()) as DAYS_SINCE_ENROLLED " +
|
||||||
|
"FROM " +
|
||||||
|
"DM_DEVICE " +
|
||||||
|
"JOIN DM_ENROLMENT ON (DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) " +
|
||||||
|
"JOIN DM_DEVICE_TYPE ON (DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID) " +
|
||||||
|
"WHERE " +
|
||||||
|
"DM_ENROLMENT.TENANT_ID = ? ";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|||||||
@ -263,6 +263,34 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - add Oracle support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add Oracle support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add Oracle support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add Oracle support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDeviceListWithoutPagination(int tenantId) throws DeviceManagementDAOException {
|
public List<Device> getDeviceListWithoutPagination(int tenantId) throws DeviceManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -179,6 +179,35 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - add PostgreSQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add PostgreSQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add PostgreSQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add PostgreSQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Return only not removed id list
|
//Return only not removed id list
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesIds(PaginationRequest request, int tenantId)
|
public List<Device> getDevicesIds(PaginationRequest request, int tenantId)
|
||||||
|
|||||||
@ -189,6 +189,35 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - add SQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add SQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedYearlyDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add SQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getNonRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - add SQL support for below billing method
|
||||||
|
@Override
|
||||||
|
public List<Device> getRemovedPriorYearsDeviceList(int tenantId, Timestamp startDate, Timestamp endDate)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Return only not removed id list
|
//Return only not removed id list
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevicesIds(PaginationRequest request, int tenantId)
|
public List<Device> getDevicesIds(PaginationRequest request, int tenantId)
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.el.lang.ELSupport;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceBilling;
|
import org.wso2.carbon.device.mgt.common.DeviceBilling;
|
||||||
@ -143,14 +144,6 @@ public final class DeviceManagementDAOUtil {
|
|||||||
|
|
||||||
public static EnrolmentInfo loadEnrolment(ResultSet rs) throws SQLException {
|
public static EnrolmentInfo loadEnrolment(ResultSet rs) throws SQLException {
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
String columnName = "LAST_BILLED_DATE";
|
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
|
||||||
int columns = rsmd.getColumnCount();
|
|
||||||
for (int x = 1; x <= columns; x++) {
|
|
||||||
if (columnName.equals(rsmd.getColumnName(x))) {
|
|
||||||
enrolmentInfo.setLastBilledDate(rs.getLong("LAST_BILLED_DATE"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
||||||
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
||||||
@ -161,15 +154,12 @@ public final class DeviceManagementDAOUtil {
|
|||||||
return enrolmentInfo;
|
return enrolmentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is used to set the enrollment data of the billing query */
|
||||||
public static EnrolmentInfo loadEnrolmentBilling(ResultSet rs) throws SQLException {
|
public static EnrolmentInfo loadEnrolmentBilling(ResultSet rs) throws SQLException {
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
|
||||||
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
||||||
enrolmentInfo.setLastBilledDate(rs.getLong("LAST_BILLED_DATE"));
|
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
if (EnrolmentInfo.Status.valueOf(rs.getString("STATUS")).equals("REMOVED")) {
|
|
||||||
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
||||||
}
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
||||||
return enrolmentInfo;
|
return enrolmentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +201,24 @@ public final class DeviceManagementDAOUtil {
|
|||||||
return enrolmentInfos.get(EnrolmentInfo.Status.SUSPENDED);
|
return enrolmentInfos.get(EnrolmentInfo.Status.SUSPENDED);
|
||||||
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.BLOCKED)) {
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.BLOCKED)) {
|
||||||
return enrolmentInfos.get(EnrolmentInfo.Status.BLOCKED);
|
return enrolmentInfos.get(EnrolmentInfo.Status.BLOCKED);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.CONFIGURED)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.CONFIGURED);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.READY_TO_CONNECT)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.READY_TO_CONNECT);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.RETURN_PENDING)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.RETURN_PENDING);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.RETURNED)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.RETURNED);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.DEFECTIVE)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.DEFECTIVE);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.WARRANTY_PENDING)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.WARRANTY_PENDING);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.WARRANTY_SENT)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.WARRANTY_SENT);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.WARRANTY_REPLACED)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.WARRANTY_REPLACED);
|
||||||
|
} else if (enrolmentInfos.containsKey(EnrolmentInfo.Status.ASSIGNED)) {
|
||||||
|
return enrolmentInfos.get(EnrolmentInfo.Status.ASSIGNED);
|
||||||
}
|
}
|
||||||
return enrolmentInfo;
|
return enrolmentInfo;
|
||||||
}
|
}
|
||||||
@ -226,29 +234,23 @@ public final class DeviceManagementDAOUtil {
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is used to set the device data of the billing query */
|
||||||
|
public static Device loadDeviceBilling(ResultSet rs) throws SQLException {
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(rs.getInt("DEVICE_ID"));
|
||||||
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
|
device.setName(rs.getString("DESCRIPTION"));
|
||||||
|
device.setDescription(rs.getString("NAME"));
|
||||||
|
device.setEnrolmentInfo(loadEnrolmentBilling(rs));
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
public static Device loadDeviceIds(ResultSet rs) throws SQLException {
|
public static Device loadDeviceIds(ResultSet rs) throws SQLException {
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setId(rs.getInt("DEVICE_ID"));
|
device.setId(rs.getInt("DEVICE_ID"));
|
||||||
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
device.setEnrolmentInfo(loadEnrolmentStatus(rs));
|
device.setEnrolmentInfo(loadEnrolmentStatus(rs));
|
||||||
return device;
|
return device;
|
||||||
}
|
|
||||||
|
|
||||||
public static DeviceBilling loadDeviceBilling(ResultSet rs) throws SQLException {
|
|
||||||
DeviceBilling device = new DeviceBilling();
|
|
||||||
device.setId(rs.getInt("ID"));
|
|
||||||
device.setName(rs.getString("DEVICE_NAME"));
|
|
||||||
device.setDescription(rs.getString("DESCRIPTION"));
|
|
||||||
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
||||||
device.setDaysUsed((int) rs.getLong("DAYS_SINCE_ENROLLED"));
|
|
||||||
device.setEnrolmentInfo(loadEnrolmentBilling(rs));
|
|
||||||
return device;
|
|
||||||
// if (removedDevices) {
|
|
||||||
// device.setDaysUsed((int) rs.getLong("DAYS_USED"));
|
|
||||||
// } else {
|
|
||||||
// device.setDaysSinceEnrolled((int) rs.getLong("DAYS_SINCE_ENROLLED"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeviceMonitoringData loadDevice(ResultSet rs, String deviceTypeName) throws SQLException {
|
public static DeviceMonitoringData loadDevice(ResultSet rs, String deviceTypeName) throws SQLException {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentType;
|
|||||||
import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata;
|
import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata;
|
||||||
import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes;
|
import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes;
|
||||||
import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
|
import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
|
||||||
|
import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.OTPManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.OTPManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
@ -78,18 +79,19 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException {
|
public String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException {
|
||||||
Tenant tenant = validateTenantCreatingDetails(otpWrapper);
|
Tenant tenant = validateTenantCreatingDetails(otpWrapper);
|
||||||
OneTimePinDTO oneTimePinDTO = createOneTimePin(otpWrapper.getEmail(), otpWrapper.getEmailType(),
|
OneTimePinDTO oneTimePinDTO = createOneTimePin(otpWrapper.getEmail(), otpWrapper.getEmailType(),
|
||||||
otpWrapper.getUsername(), tenant, -1234);
|
otpWrapper.getUsername(), tenant, -1234);
|
||||||
try {
|
try {
|
||||||
ConnectionManagerUtil.beginDBTransaction();
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
this.otpManagementDAO.addOTPData(Collections.singletonList(oneTimePinDTO));
|
this.otpManagementDAO.addOTPData(Collections.singletonList(oneTimePinDTO));
|
||||||
Properties props = new Properties();
|
// Properties props = new Properties();
|
||||||
props.setProperty("first-name", tenant.getAdminFirstName());
|
// props.setProperty("first-name", tenant.getAdminFirstName());
|
||||||
props.setProperty("otp-token", oneTimePinDTO.getOtpToken());
|
// props.setProperty("otp-token", oneTimePinDTO.getOtpToken());
|
||||||
sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE);
|
// sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE);
|
||||||
ConnectionManagerUtil.commitDBTransaction();
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
return oneTimePinDTO.getOtpToken();
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
String msg = "Error occurred while disabling AutoCommit.";
|
String msg = "Error occurred while disabling AutoCommit.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -108,6 +110,31 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException {
|
||||||
|
if (StringUtils.isBlank(downloadURLDetails.getURL())) {
|
||||||
|
String msg = "Couldn't find the download URL with the request.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new OTPManagementException(msg);
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(downloadURLDetails.getFirstName())) {
|
||||||
|
String msg = "Couldn't find the First Name with the request.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new OTPManagementException(msg);
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(downloadURLDetails.getEmail())) {
|
||||||
|
String msg = "Couldn't find the e-mail address with the request.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new OTPManagementException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("first-name", downloadURLDetails.getFirstName());
|
||||||
|
props.setProperty("download-url", downloadURLDetails.getURL());
|
||||||
|
sendMail(props, downloadURLDetails.getEmail(),
|
||||||
|
DeviceManagementConstants.EmailAttributes.PRODUCT_DOWNLOAD_LINK_SHARING_TEMPLATE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException {
|
public OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException {
|
||||||
if (StringUtils.isBlank(oneTimeToken)){
|
if (StringUtils.isBlank(oneTimeToken)){
|
||||||
|
|||||||
@ -208,16 +208,6 @@ public interface DeviceManagementProviderService {
|
|||||||
*/
|
*/
|
||||||
PaginationResult getAllDevices(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
|
PaginationResult getAllDevices(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to retrieve all the devices with pagination support.
|
|
||||||
*
|
|
||||||
* @param request PaginationRequest object holding the data for pagination
|
|
||||||
* @return PaginationResult - Result including the required parameters necessary to do pagination.
|
|
||||||
* @throws DeviceManagementException If some unusual behaviour is observed while fetching billing of
|
|
||||||
* devices.
|
|
||||||
*/
|
|
||||||
PaginationResult getAllDevicesBillings(PaginationRequest request, int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate, boolean generateBill) throws DeviceManagementException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve all the devices with pagination support.
|
* Method to retrieve all the devices with pagination support.
|
||||||
*
|
*
|
||||||
@ -225,9 +215,7 @@ public interface DeviceManagementProviderService {
|
|||||||
* @throws DeviceManagementException If some unusual behaviour is observed while fetching billing of
|
* @throws DeviceManagementException If some unusual behaviour is observed while fetching billing of
|
||||||
* devices.
|
* devices.
|
||||||
*/
|
*/
|
||||||
PaginationResult createBillingFile(int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate, boolean generateBill) throws DeviceManagementException;
|
PaginationResult createBillingFile(int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve all the devices with pagination support.
|
* Method to retrieve all the devices with pagination support.
|
||||||
|
|||||||
@ -69,8 +69,10 @@ import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.BillingResponse;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.MobileAppTypes;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
@ -119,12 +121,12 @@ import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypePlatformVersion;
|
|||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
||||||
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
|
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.impl.BillingCacheManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl;
|
import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.common.Constants;
|
import org.wso2.carbon.device.mgt.core.common.Constants;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
|
import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.BillingDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
@ -142,6 +144,7 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
|
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
|
||||||
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataDAO;
|
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
@ -166,8 +169,7 @@ import java.io.StringWriter;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.Format;
|
import java.time.LocalDateTime;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -195,7 +197,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
private final EnrollmentDAO enrollmentDAO;
|
private final EnrollmentDAO enrollmentDAO;
|
||||||
private final ApplicationDAO applicationDAO;
|
private final ApplicationDAO applicationDAO;
|
||||||
private MetadataDAO metadataDAO;
|
private MetadataDAO metadataDAO;
|
||||||
private final BillingDAO billingDAO;
|
|
||||||
private final DeviceStatusDAO deviceStatusDAO;
|
private final DeviceStatusDAO deviceStatusDAO;
|
||||||
|
|
||||||
public DeviceManagementProviderServiceImpl() {
|
public DeviceManagementProviderServiceImpl() {
|
||||||
@ -205,7 +206,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
||||||
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
||||||
this.billingDAO = DeviceManagementDAOFactory.getBillingDAO();
|
|
||||||
this.deviceStatusDAO = DeviceManagementDAOFactory.getDeviceStatusDAO();
|
this.deviceStatusDAO = DeviceManagementDAOFactory.getDeviceStatusDAO();
|
||||||
|
|
||||||
/* Registering a listener to retrieve events when some device management service plugin is installed after
|
/* Registering a listener to retrieve events when some device management service plugin is installed after
|
||||||
@ -529,6 +529,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
extractDeviceLocationToUpdate(device);
|
extractDeviceLocationToUpdate(device);
|
||||||
|
//enroll Traccar device
|
||||||
|
if (HttpReportingUtil.isTrackerEnabled()) {
|
||||||
|
try {
|
||||||
|
int tenantId = this.getTenantId();
|
||||||
|
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().modifyDevice(device, tenantId);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
log.error("ExecutionException : " + e);
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
//Exception was not thrown due to being conflicted with non-traccar features
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("InterruptedException : " + e);
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
//Exception was not thrown due to being conflicted with non-traccar features
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("Traccar is disabled");
|
||||||
|
}
|
||||||
|
//enroll Traccar device
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,236 +1023,232 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return this.getAllDevices(request, true);
|
return this.getAllDevices(request, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaginationResult calculateCost(int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate, boolean generateBill, List<Device> allDevices) throws DeviceManagementException {
|
/**
|
||||||
|
* Calculate cost of a tenants Device List.
|
||||||
|
* Once the full device list of a tenant is sent here devices are looped for cost calculation
|
||||||
|
* Cost per tenant is retrieved from the Meta Table
|
||||||
|
* When looping the devices the most recent device status of that device is retrieved from status table
|
||||||
|
* If device is enrolled prior to start date now in removed state --> time is calculated from - startDate to last updated time
|
||||||
|
* If device is enrolled prior to start date now in not removed --> time is calculated from - startDate to endDate
|
||||||
|
* If device is enrolled after the start date now in removed state --> time is calculated from - dateOfEnrollment to last updated time
|
||||||
|
* If device is enrolled after the start date now in not removed --> time is calculated from - dateOfEnrollment to endDate
|
||||||
|
* Once time is calculated cost is set for each device
|
||||||
|
*
|
||||||
|
* @param tenantDomain Tenant domain cost id calculated for.
|
||||||
|
* @param startDate start date of usage period.
|
||||||
|
* @param endDate end date of usage period.
|
||||||
|
* @param allDevices device list of the tenant for the selected time-period.
|
||||||
|
* @return Whether status is changed or not
|
||||||
|
* @throws DeviceManagementException on errors while trying to calculate Cost
|
||||||
|
*/
|
||||||
|
public BillingResponse calculateCost(String tenantDomain, Timestamp startDate, Timestamp endDate, List<Device> allDevices) throws MetadataManagementDAOException, DeviceManagementException {
|
||||||
|
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
BillingResponse billingResponse = new BillingResponse();
|
||||||
|
List<Device> deviceStatusNotAvailable = new ArrayList<>();
|
||||||
double totalCost = 0.0;
|
double totalCost = 0.0;
|
||||||
boolean allDevicesBilledDateIsValid = true;
|
|
||||||
ArrayList<String> lastBilledDatesList = new ArrayList<>();
|
|
||||||
List<Billing> invalidDevices = new ArrayList<>();
|
|
||||||
List<Device> removeBillingPeriodInvalidDevices = new ArrayList<>() ;
|
|
||||||
List<Device> removeStatusUpdateInvalidDevices = new ArrayList<>() ;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetadataManagementDAOFactory.beginTransaction();
|
MetadataManagementDAOFactory.openConnection();
|
||||||
Metadata metadata = metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, DeviceManagementConstants.META_KEY);
|
Metadata metadata = metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, DeviceManagementConstants.META_KEY);
|
||||||
|
|
||||||
Gson g = new Gson();
|
Gson g = new Gson();
|
||||||
Collection<Cost> costData = null;
|
Collection<Cost> costData = null;
|
||||||
|
|
||||||
|
Type collectionType = new TypeToken<Collection<Cost>>() {
|
||||||
Type collectionType = new TypeToken<Collection<Cost>>() {}.getType();
|
}.getType();
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
costData = g.fromJson(metadata.getMetaValue(), collectionType);
|
costData = g.fromJson(metadata.getMetaValue(), collectionType);
|
||||||
for (Cost tenantCost : costData) {
|
for (Cost tenantCost : costData) {
|
||||||
if (tenantCost.getTenantDomain().equals(tenantDomain)) {
|
if (tenantCost.getTenantDomain().equals(tenantDomain)) {
|
||||||
for (Device device : allDevices) {
|
for (Device device : allDevices) {
|
||||||
device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, null, true));
|
|
||||||
long dateDiff = 0;
|
long dateDiff = 0;
|
||||||
|
device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, endDate, true));
|
||||||
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
|
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
|
||||||
boolean firstDateBilled = false;
|
if (device.getEnrolmentInfo().getDateOfEnrolment() < startDate.getTime()) {
|
||||||
boolean deviceStatusIsValid = false;
|
if (!deviceStatus.isEmpty() && deviceStatus.get(0).getStatus().equals("REMOVED")) {
|
||||||
|
if (deviceStatus.get(0).getUpdateTime().getTime() >= startDate.getTime()) {
|
||||||
List<Billing> deviceBilling = billingDAO.getBilling(device.getId(), startDate, endDate);
|
dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - startDate.getTime();
|
||||||
boolean billDateIsInvalid = false;
|
|
||||||
|
|
||||||
if (deviceBilling.isEmpty()) {
|
|
||||||
billDateIsInvalid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (generateBill) {
|
|
||||||
for (Billing bill : deviceBilling) {
|
|
||||||
if ((bill.getBillingStart() <= startDate.getTime() && startDate.getTime() <= bill.getBillingEnd()) ||
|
|
||||||
(bill.getBillingStart() <= endDate.getTime() && endDate.getTime() <= bill.getBillingEnd())) {
|
|
||||||
billDateIsInvalid = true;
|
|
||||||
invalidDevices.add(bill);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!billDateIsInvalid) {
|
|
||||||
for (int i = 0; i < deviceStatus.size(); i++) {
|
|
||||||
if (DeviceManagementConstants.ACTIVE_STATUS.equals(deviceStatus.get(i).getStatus().toString())) {
|
|
||||||
if (deviceStatus.size() > i + 1) {
|
|
||||||
if (!firstDateBilled) {
|
|
||||||
firstDateBilled = true;
|
|
||||||
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
||||||
} else {
|
|
||||||
if (deviceStatus.get(i + 1).getUpdateTime().getTime() >= device.getEnrolmentInfo().getLastBilledDate()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - device.getEnrolmentInfo().getLastBilledDate());
|
|
||||||
}
|
}
|
||||||
|
} else if (!deviceStatus.isEmpty() && !deviceStatus.get(0).getStatus().equals("REMOVED")) {
|
||||||
|
dateDiff = endDate.getTime() - startDate.getTime();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (deviceStatus.get(i).getUpdateTime().getTime() >= device.getEnrolmentInfo().getLastBilledDate()) {
|
if (!deviceStatus.isEmpty() && deviceStatus.get(0).getStatus().equals("REMOVED")) {
|
||||||
deviceStatusIsValid = true;
|
if (deviceStatus.get(0).getUpdateTime().getTime() >= device.getEnrolmentInfo().getDateOfEnrolment()) {
|
||||||
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - device.getEnrolmentInfo().getDateOfEnrolment();
|
||||||
|
}
|
||||||
|
} else if (!deviceStatus.isEmpty() && !deviceStatus.get(0).getStatus().equals("REMOVED")) {
|
||||||
|
dateDiff = endDate.getTime() - device.getEnrolmentInfo().getDateOfEnrolment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
|
||||||
// If only one status row is retrieved this block is executed
|
|
||||||
if (!firstDateBilled) {
|
|
||||||
firstDateBilled = true;
|
|
||||||
|
|
||||||
// Is executed if there is no lastBilled date and if the updates time is before the end date
|
|
||||||
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
||||||
if (endDate.getTime() >= deviceStatus.get(i).getUpdateTime().getTime()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (endDate.getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (endDate.getTime() >= device.getEnrolmentInfo().getLastBilledDate()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (endDate.getTime() - device.getEnrolmentInfo().getLastBilledDate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (device.getEnrolmentInfo().getLastBilledDate() <= deviceStatus.get(i).getUpdateTime().getTime()
|
|
||||||
&& endDate.getTime() >= deviceStatus.get(i).getUpdateTime().getTime()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (endDate.getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
||||||
}
|
|
||||||
if (device.getEnrolmentInfo().getLastBilledDate() >= deviceStatus.get(i).getUpdateTime().getTime()
|
|
||||||
&& endDate.getTime() >= device.getEnrolmentInfo().getLastBilledDate()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
dateDiff = dateDiff + (endDate.getTime() - device.getEnrolmentInfo().getLastBilledDate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long dateInDays = TimeUnit.DAYS.convert(dateDiff, TimeUnit.MILLISECONDS);
|
long dateInDays = TimeUnit.DAYS.convert(dateDiff, TimeUnit.MILLISECONDS);
|
||||||
double cost = (tenantCost.getCost() / 365) * dateInDays;
|
double cost = (tenantCost.getCost() / 365) * dateInDays;
|
||||||
totalCost = cost + totalCost;
|
totalCost += cost;
|
||||||
device.setCost(Math.round(cost * 100.0) / 100.0);
|
device.setCost(Math.round(cost * 100.0) / 100.0);
|
||||||
device.setDaysUsed((int) dateInDays);
|
long totalDays = dateInDays + device.getDaysUsed();
|
||||||
|
device.setDaysUsed((int) totalDays);
|
||||||
if (generateBill) {
|
if (deviceStatus.isEmpty()) {
|
||||||
enrollmentDAO.updateEnrollmentLastBilledDate(device.getEnrolmentInfo(), endDate, tenantId);
|
deviceStatusNotAvailable.add(device);
|
||||||
billingDAO.addBilling(device.getId(), tenantId, startDate, endDate);
|
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
for (int i = 0; i < deviceStatus.size(); i++) {
|
|
||||||
if (endDate.getTime() >= deviceStatus.get(i).getUpdateTime().getTime()
|
|
||||||
&& startDate.getTime() <= deviceStatus.get(i).getUpdateTime().getTime()) {
|
|
||||||
deviceStatusIsValid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (device.getEnrolmentInfo().getLastBilledDate() != 0) {
|
|
||||||
Date date = new Date(device.getEnrolmentInfo().getLastBilledDate());
|
|
||||||
Format format = new SimpleDateFormat("yyyy MM dd");
|
|
||||||
|
|
||||||
for (String lastBillDate : lastBilledDatesList) {
|
|
||||||
if (!lastBillDate.equals(format.format(date))) {
|
|
||||||
lastBilledDatesList.add(format.format(date));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removeBillingPeriodInvalidDevices.add(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!deviceStatusIsValid) {
|
|
||||||
removeStatusUpdateInvalidDevices.add(device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving device list pertaining to the current tenant";
|
String msg = "Error occurred calculating cost of devices";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (Exception e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred in getAllDevices";
|
String msg = "Error when retrieving data";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error when retrieving metadata of billing feature";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MetadataManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deviceStatusNotAvailable.isEmpty()) {
|
||||||
|
allDevices.removeAll(deviceStatusNotAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar calStart = Calendar.getInstance();
|
||||||
|
Calendar calEnd = Calendar.getInstance();
|
||||||
|
calStart.setTimeInMillis(startDate.getTime());
|
||||||
|
calEnd.setTimeInMillis(endDate.getTime());
|
||||||
|
|
||||||
|
billingResponse.setDevice(allDevices);
|
||||||
|
billingResponse.setYear(String.valueOf(calStart.get(Calendar.YEAR)));
|
||||||
|
billingResponse.setStartDate(startDate.toString());
|
||||||
|
billingResponse.setEndDate(endDate.toString());
|
||||||
|
billingResponse.setBillPeriod(calStart.get(Calendar.YEAR) + " - " + calEnd.get(Calendar.YEAR));
|
||||||
|
billingResponse.setTotalCostPerYear(Math.round(totalCost * 100.0) / 100.0);
|
||||||
|
billingResponse.setDeviceCount(allDevices.size());
|
||||||
|
|
||||||
|
return billingResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult createBillingFile(int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||||
|
|
||||||
|
PaginationResult paginationResult = new PaginationResult();
|
||||||
|
List<Device> allDevices = new ArrayList<>();
|
||||||
|
List<BillingResponse> billingResponseList = new ArrayList<>();
|
||||||
|
double totalCost = 0.0;
|
||||||
|
int deviceCount = 0;
|
||||||
|
Timestamp initialStartDate = startDate;
|
||||||
|
boolean remainingDaysConsidered = false;
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
|
||||||
|
// TODO Do the check of cache enabling here
|
||||||
|
paginationResult = BillingCacheManagerImpl.getInstance().getBillingFromCache(tenantDomain, startDate, endDate);
|
||||||
|
if (paginationResult == null) {
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
long difference_In_Time = endDate.getTime() - startDate.getTime();
|
||||||
|
|
||||||
|
long difference_In_Years = (difference_In_Time / (1000L * 60 * 60 * 24 * 365));
|
||||||
|
|
||||||
|
long difference_In_Days = (difference_In_Time / (1000 * 60 * 60 * 24)) % 365;
|
||||||
|
|
||||||
|
for (int i = 1; i <= difference_In_Years; i++) {
|
||||||
|
List<Device> allDevicesPerYear = new ArrayList<>();
|
||||||
|
LocalDateTime oneYearAfterStart = startDate.toLocalDateTime().plusYears(1);
|
||||||
|
Timestamp newStartDate;
|
||||||
|
Timestamp newEndDate;
|
||||||
|
|
||||||
|
if (i == difference_In_Years) {
|
||||||
|
if (difference_In_Days == 0 || Timestamp.valueOf(oneYearAfterStart).getTime() >= endDate.getTime()) {
|
||||||
|
remainingDaysConsidered = true;
|
||||||
|
oneYearAfterStart = startDate.toLocalDateTime();
|
||||||
|
newEndDate = endDate;
|
||||||
|
} else if (Timestamp.valueOf(oneYearAfterStart).getTime() >= endDate.getTime()) {
|
||||||
|
newEndDate = Timestamp.valueOf(oneYearAfterStart);
|
||||||
|
} else {
|
||||||
|
oneYearAfterStart = startDate.toLocalDateTime().plusYears(1);
|
||||||
|
newEndDate = Timestamp.valueOf(oneYearAfterStart);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
oneYearAfterStart = startDate.toLocalDateTime().plusYears(1);
|
||||||
|
newEndDate = Timestamp.valueOf(oneYearAfterStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
newStartDate = startDate;
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled in this year now in not removed state
|
||||||
|
allDevicesPerYear.addAll(deviceDAO.getNonRemovedYearlyDeviceList(tenantId, newStartDate, newEndDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled in this year now in removed state
|
||||||
|
allDevicesPerYear.addAll(deviceDAO.getRemovedYearlyDeviceList(tenantId, newStartDate, newEndDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled prior this year now in not removed state
|
||||||
|
allDevicesPerYear.addAll(deviceDAO.getNonRemovedPriorYearsDeviceList(tenantId, newStartDate, newEndDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled prior this year now in removed state
|
||||||
|
allDevicesPerYear.addAll(deviceDAO.getRemovedPriorYearsDeviceList(tenantId, newStartDate, newEndDate));
|
||||||
|
|
||||||
|
BillingResponse billingResponse = calculateCost(tenantDomain, newStartDate, newEndDate, allDevicesPerYear);
|
||||||
|
billingResponseList.add(billingResponse);
|
||||||
|
allDevices.addAll(billingResponse.getDevice());
|
||||||
|
totalCost = totalCost + billingResponse.getTotalCostPerYear();
|
||||||
|
deviceCount = deviceCount + billingResponse.getDeviceCount();
|
||||||
|
LocalDateTime nextStartDate = oneYearAfterStart.plusDays(1);
|
||||||
|
startDate = Timestamp.valueOf(nextStartDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (difference_In_Days != 0 && !remainingDaysConsidered) {
|
||||||
|
List<Device> allDevicesPerRemainingDays = new ArrayList<>();
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled in this year now in not removed state
|
||||||
|
allDevicesPerRemainingDays.addAll(deviceDAO.getNonRemovedYearlyDeviceList(tenantId, startDate, endDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled in this year now in removed state
|
||||||
|
allDevicesPerRemainingDays.addAll(deviceDAO.getRemovedYearlyDeviceList(tenantId, startDate, endDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled prior this year now in not removed state
|
||||||
|
allDevicesPerRemainingDays.addAll(deviceDAO.getNonRemovedPriorYearsDeviceList(tenantId, startDate, endDate));
|
||||||
|
|
||||||
|
// The query returns devices which are enrolled prior this year now in removed state
|
||||||
|
allDevicesPerRemainingDays.addAll(deviceDAO.getRemovedPriorYearsDeviceList(tenantId, startDate, endDate));
|
||||||
|
|
||||||
|
BillingResponse billingResponse = calculateCost(tenantDomain, startDate, endDate, allDevicesPerRemainingDays);
|
||||||
|
billingResponseList.add(billingResponse);
|
||||||
|
allDevices.addAll(billingResponse.getDevice());
|
||||||
|
totalCost = totalCost + billingResponse.getTotalCostPerYear();
|
||||||
|
deviceCount = deviceCount + billingResponse.getDeviceCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar calStart = Calendar.getInstance();
|
||||||
|
Calendar calEnd = Calendar.getInstance();
|
||||||
|
calStart.setTimeInMillis(initialStartDate.getTime());
|
||||||
|
calEnd.setTimeInMillis(endDate.getTime());
|
||||||
|
|
||||||
|
BillingResponse billingResponse = new BillingResponse("all", Math.round(totalCost * 100.0) / 100.0, allDevices, calStart.get(Calendar.YEAR) + " - " + calEnd.get(Calendar.YEAR), initialStartDate.toString(), endDate.toString(), allDevices.size());
|
||||||
|
billingResponseList.add(billingResponse);
|
||||||
|
paginationResult.setData(billingResponseList);
|
||||||
|
paginationResult.setTotalCost(Math.round(totalCost * 100.0) / 100.0);
|
||||||
|
paginationResult.setTotalDeviceCount(deviceCount);
|
||||||
|
BillingCacheManagerImpl.getInstance().addBillingToCache(paginationResult, tenantDomain, initialStartDate, endDate);
|
||||||
|
return paginationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving device bill list related to the current tenant";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} catch (MetadataManagementDAOException e) {
|
||||||
|
String msg = "Error when retrieving metadata of billing feature";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
MetadataManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!removeBillingPeriodInvalidDevices.isEmpty() && removeBillingPeriodInvalidDevices.size() == allDevices.size()) {
|
|
||||||
allDevicesBilledDateIsValid = false;
|
|
||||||
paginationResult.setMessage("Invalid bill period.");
|
|
||||||
}
|
|
||||||
if(!removeStatusUpdateInvalidDevices.isEmpty() && removeStatusUpdateInvalidDevices.size() == allDevices.size()) {
|
|
||||||
allDevicesBilledDateIsValid = false;
|
|
||||||
if (paginationResult.getMessage() != null){
|
|
||||||
paginationResult.setMessage(paginationResult.getMessage() + " and no device updates within entered bill period.");
|
|
||||||
} else {
|
|
||||||
paginationResult.setMessage("Devices have not been updated within the given period or entered end date comes before the " +
|
|
||||||
"last billed date.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
allDevices.removeAll(removeBillingPeriodInvalidDevices);
|
|
||||||
allDevices.removeAll(removeStatusUpdateInvalidDevices);
|
|
||||||
|
|
||||||
paginationResult.setBilledDateIsValid(allDevicesBilledDateIsValid);
|
|
||||||
paginationResult.setData(allDevices);
|
|
||||||
paginationResult.setTotalCost(Math.round(totalCost * 100.0) / 100.0);
|
|
||||||
return paginationResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PaginationResult getAllDevicesBillings(PaginationRequest request, int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate, boolean generateBill) throws DeviceManagementException {
|
|
||||||
if (request == null) {
|
|
||||||
String msg = "Received incomplete pagination request for method getAllDeviceBillings";
|
|
||||||
log.error(msg);
|
|
||||||
throw new DeviceManagementException(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManagerUtil.validateDeviceListPageSize(request);
|
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
|
||||||
List<Device> allDevices;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
|
||||||
allDevices = deviceDAO.getDevices(request, tenantId);
|
|
||||||
count = deviceDAO.getDeviceCount(request, tenantId);
|
|
||||||
paginationResult = calculateCost(tenantId, tenantDomain, startDate, endDate, generateBill, allDevices);
|
|
||||||
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
String msg = "Error occurred while retrieving device bill list pertaining to the current tenant";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred in getAllDevicesBillings";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
}
|
|
||||||
paginationResult.setRecordsFiltered(count);
|
|
||||||
paginationResult.setRecordsTotal(count);
|
|
||||||
return paginationResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PaginationResult createBillingFile(int tenantId, String tenantDomain, Timestamp startDate, Timestamp endDate, boolean generateBill) throws DeviceManagementException {
|
|
||||||
PaginationResult paginationResult = new PaginationResult();
|
|
||||||
List<Device> allDevices;
|
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
|
||||||
allDevices = deviceDAO.getDeviceListWithoutPagination(tenantId);
|
|
||||||
paginationResult = calculateCost(tenantId, tenantDomain, startDate, endDate, generateBill, allDevices);
|
|
||||||
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
String msg = "Error occurred while retrieving device bill list without pagination pertaining to the current tenant";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred in createBillingFile";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
}
|
}
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||||
@ -54,12 +55,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
|||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.*;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
import org.wso2.carbon.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
||||||
import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
@ -76,6 +72,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -144,13 +141,16 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
if (HttpReportingUtil.isTrackerEnabled()){
|
if (HttpReportingUtil.isTrackerEnabled()){
|
||||||
existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
||||||
int groupId = existingGroup.getGroupId();
|
int groupId = existingGroup.getGroupId();
|
||||||
|
try {
|
||||||
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
|
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
|
||||||
.addGroup(deviceGroup, groupId, tenantId);
|
.addGroup(deviceGroup, groupId, tenantId);
|
||||||
}
|
} catch (TrackerAlreadyExistException e) {
|
||||||
// add a group if not exist in traccar starts
|
|
||||||
|
|
||||||
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (GroupManagementDAOException e) {
|
} catch (GroupManagementDAOException e) {
|
||||||
GroupManagementDAOFactory.rollbackTransaction();
|
GroupManagementDAOFactory.rollbackTransaction();
|
||||||
String msg = "Error occurred while adding deviceGroup '" + deviceGroup.getName() + "' to database.";
|
String msg = "Error occurred while adding deviceGroup '" + deviceGroup.getName() + "' to database.";
|
||||||
@ -194,8 +194,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
GroupManagementDAOFactory.beginTransaction();
|
GroupManagementDAOFactory.beginTransaction();
|
||||||
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
|
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
|
||||||
if (existingGroup != null) {
|
if (existingGroup != null) {
|
||||||
boolean existingGroupName = this.groupDAO.getGroup(deviceGroup.getName(), tenantId) != null;
|
DeviceGroup existingGroupByName = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
|
||||||
if (existingGroupName) {
|
if (existingGroupByName != null && existingGroupByName.getGroupId() != groupId) {
|
||||||
throw new GroupAlreadyExistException("Group already exists with name '" + deviceGroup.getName() + "'.");
|
throw new GroupAlreadyExistException("Group already exists with name '" + deviceGroup.getName() + "'.");
|
||||||
}
|
}
|
||||||
List<DeviceGroup> groupsToUpdate = new ArrayList<>();
|
List<DeviceGroup> groupsToUpdate = new ArrayList<>();
|
||||||
@ -299,8 +299,16 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
|
|
||||||
//procees to delete a group from traccar starts
|
//procees to delete a group from traccar starts
|
||||||
if (HttpReportingUtil.isTrackerEnabled()) {
|
if (HttpReportingUtil.isTrackerEnabled()) {
|
||||||
|
try {
|
||||||
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
|
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
|
||||||
.deleteGroup(groupId, tenantId);
|
.deleteGroup(groupId, tenantId);
|
||||||
|
} catch (TrackerManagementDAOException e) {
|
||||||
|
String msg = "Failed while deleting traccar group " + groupId;
|
||||||
|
log.error(msg, e);
|
||||||
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
|
String msg = "Failed while deleting traccar group "+groupId+" due to concurrent execution failure";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//procees to delete a group from traccar ends
|
//procees to delete a group from traccar ends
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,14 @@ public interface DeviceAPIClientService {
|
|||||||
*/
|
*/
|
||||||
void addDevice(Device device, int tenantId) throws ExecutionException, InterruptedException;
|
void addDevice(Device device, int tenantId) throws ExecutionException, InterruptedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates device Traccar configuration records (like device name)
|
||||||
|
*
|
||||||
|
* @params device to be modifies
|
||||||
|
* @throws TrackerManagementDAOException errors thrown while modifing a traccar device
|
||||||
|
*/
|
||||||
|
void modifyDevice(Device device, int tenantId) throws ExecutionException, InterruptedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a device Traccar configuration records
|
* Delete a device Traccar configuration records
|
||||||
*
|
*
|
||||||
|
|||||||
@ -469,6 +469,54 @@ public class TraccarClientFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the Device
|
||||||
|
*
|
||||||
|
* @param traccarDevice with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId
|
||||||
|
* Model, Contact, Category, fenceIds
|
||||||
|
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation
|
||||||
|
*/
|
||||||
|
public void modifyDevice(TraccarDevice traccarDevice, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException {
|
||||||
|
TrackerDeviceInfo trackerDeviceInfo = null;
|
||||||
|
try {
|
||||||
|
TrackerManagementDAOFactory.openConnection();
|
||||||
|
trackerDeviceInfo = trackerDAO.getTrackerDevice(traccarDevice.getId(), tenantId);
|
||||||
|
} catch (TrackerManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while mapping with deviceId .";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new TrackerManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred establishing the DB connection .";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new TrackerManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
TrackerManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
if (trackerDeviceInfo != null) {
|
||||||
|
log.info("Preparing to rename device (" + traccarDevice.getId() + " to taccar server");
|
||||||
|
String url = defaultPort + "/api/devices/" + trackerDeviceInfo.getTraccarDeviceId();
|
||||||
|
JSONObject payload = TraccarUtil.TraccarDevicePayload(traccarDevice, trackerDeviceInfo.getTraccarDeviceId());
|
||||||
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT,
|
||||||
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
||||||
|
serverUrl(HttpReportingUtil.trackerServer())));
|
||||||
|
String result = res.get();
|
||||||
|
log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar.");
|
||||||
|
if (res.isDone() && result.charAt(0) == '{') {
|
||||||
|
log.info("Succesfully renamed Traccar Device - " + traccarDevice.getId() + "in server");
|
||||||
|
} else {
|
||||||
|
log.info("Failed to rename Traccar Device" + traccarDevice.getId() + "in server");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// forward to add device
|
||||||
|
try {
|
||||||
|
addDevice(traccarDevice, tenantId);
|
||||||
|
} catch (TrackerAlreadyExistException e) {
|
||||||
|
String msg = "The device already exist";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Device GPS Location operation.
|
* Add Device GPS Location operation.
|
||||||
*
|
*
|
||||||
@ -600,7 +648,7 @@ public class TraccarClientFactory {
|
|||||||
TrackerManagementDAOFactory.openConnection();
|
TrackerManagementDAOFactory.openConnection();
|
||||||
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
||||||
if (trackerGroupInfo != null) {
|
if (trackerGroupInfo != null) {
|
||||||
String msg = "The group already exit";
|
String msg = "The group already exists in Traccar.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new TrackerAlreadyExistException(msg);
|
throw new TrackerAlreadyExistException(msg);
|
||||||
}
|
}
|
||||||
@ -626,7 +674,9 @@ public class TraccarClientFactory {
|
|||||||
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
||||||
serverUrl(HttpReportingUtil.trackerServer())));
|
serverUrl(HttpReportingUtil.trackerServer())));
|
||||||
String result = res.get();
|
String result = res.get();
|
||||||
|
if (null != trackerGroupInfo) {
|
||||||
log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar.");
|
log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar.");
|
||||||
|
}
|
||||||
if (res.isDone() && result.charAt(0) == '{') {
|
if (res.isDone() && result.charAt(0) == '{') {
|
||||||
JSONObject obj = new JSONObject(result);
|
JSONObject obj = new JSONObject(result);
|
||||||
if (obj.has("id")) {
|
if (obj.has("id")) {
|
||||||
|
|||||||
@ -555,7 +555,7 @@ public class TraccarClientImpl implements TraccarClient {
|
|||||||
TrackerManagementDAOFactory.openConnection();
|
TrackerManagementDAOFactory.openConnection();
|
||||||
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
||||||
if (trackerGroupInfo != null) {
|
if (trackerGroupInfo != null) {
|
||||||
String msg = "The group already exit";
|
String msg = "The group already exists in Traccar.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new TrackerAlreadyExistException(msg);
|
throw new TrackerAlreadyExistException(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,17 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifyDevice(Device device, int tenantId) throws ExecutionException, InterruptedException {
|
||||||
|
TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getDeviceIdentifier(), device.getName());
|
||||||
|
try {
|
||||||
|
client.modifyDevice(traccarDevice, tenantId);
|
||||||
|
} catch (TrackerManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while mapping with deviceId";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) throws ExecutionException, InterruptedException {
|
public void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) throws ExecutionException, InterruptedException {
|
||||||
TraccarPosition traccarPosition = new TraccarPosition(device.getDeviceIdentifier(),
|
TraccarPosition traccarPosition = new TraccarPosition(device.getDeviceIdentifier(),
|
||||||
|
|||||||
@ -55,6 +55,12 @@ public class TraccarDevice {
|
|||||||
this.category =category;
|
this.category =category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TraccarDevice(int id, String uniqueId, String deviceName) {
|
||||||
|
this.id = id;
|
||||||
|
this.uniqueId = uniqueId;
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
public TraccarDevice(){ }
|
public TraccarDevice(){ }
|
||||||
|
|
||||||
public int getId() { return id; }
|
public int getId() { return id; }
|
||||||
|
|||||||
@ -66,4 +66,12 @@ public class TraccarUtil {
|
|||||||
payload.put("attributes", new JSONObject());
|
payload.put("attributes", new JSONObject());
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JSONObject TraccarDevicePayload(TraccarDevice deviceInfo, int id) {
|
||||||
|
JSONObject payload = new JSONObject();
|
||||||
|
payload.put("id", id);
|
||||||
|
payload.put("name", deviceInfo.getDeviceName());
|
||||||
|
payload.put("uniqueId", deviceInfo.getUniqueId());
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
||||||
@ -76,6 +77,7 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
|
|||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.BillingCacheKey;
|
||||||
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
|
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
|
||||||
import org.wso2.carbon.device.mgt.core.cache.GeoCacheKey;
|
import org.wso2.carbon.device.mgt.core.cache.GeoCacheKey;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
@ -137,6 +139,7 @@ public final class DeviceManagerUtil {
|
|||||||
public static final String GENERAL_CONFIG_RESOURCE_PATH = "general";
|
public static final String GENERAL_CONFIG_RESOURCE_PATH = "general";
|
||||||
|
|
||||||
private static boolean isDeviceCacheInitialized = false;
|
private static boolean isDeviceCacheInitialized = false;
|
||||||
|
private static boolean isBillingCacheInitialized = false;
|
||||||
private static boolean isAPIResourcePermissionCacheInitialized = false;
|
private static boolean isAPIResourcePermissionCacheInitialized = false;
|
||||||
private static boolean isGeoFenceCacheInitialized = false;
|
private static boolean isGeoFenceCacheInitialized = false;
|
||||||
|
|
||||||
@ -652,6 +655,47 @@ public final class DeviceManagerUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable Billing caching according to the configurations provided by cdm-config.xml
|
||||||
|
*/
|
||||||
|
public static void initializeBillingCache() {
|
||||||
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
int billingCacheExpiry = config.getBillingCacheConfiguration().getExpiryTime();
|
||||||
|
long billingCacheCapacity = config.getBillingCacheConfiguration().getCapacity();
|
||||||
|
CacheManager manager = getCacheManager();
|
||||||
|
if (config.getBillingCacheConfiguration().isEnabled()) {
|
||||||
|
if(!isBillingCacheInitialized) {
|
||||||
|
isBillingCacheInitialized = true;
|
||||||
|
if (manager != null) {
|
||||||
|
if (billingCacheExpiry > 0) {
|
||||||
|
manager.<BillingCacheKey, PaginationResult>createCacheBuilder(DeviceManagementConstants.BILLING_CACHE).
|
||||||
|
setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS,
|
||||||
|
billingCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
||||||
|
Duration(TimeUnit.SECONDS, billingCacheExpiry)).setStoreByValue(true).build();
|
||||||
|
if(billingCacheCapacity > 0 ) {
|
||||||
|
((CacheImpl) manager.<BillingCacheKey, PaginationResult>getCache(DeviceManagementConstants.BILLING_CACHE)).
|
||||||
|
setCapacity(billingCacheCapacity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
manager.<BillingCacheKey, PaginationResult>getCache(DeviceManagementConstants.BILLING_CACHE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (billingCacheExpiry > 0) {
|
||||||
|
Caching.getCacheManager().
|
||||||
|
<BillingCacheKey, PaginationResult>createCacheBuilder(DeviceManagementConstants.BILLING_CACHE).
|
||||||
|
setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS,
|
||||||
|
billingCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
||||||
|
Duration(TimeUnit.SECONDS, billingCacheExpiry)).setStoreByValue(true).build();
|
||||||
|
((CacheImpl)(manager.<BillingCacheKey, PaginationResult>getCache(DeviceManagementConstants.BILLING_CACHE))).
|
||||||
|
setCapacity(billingCacheCapacity);
|
||||||
|
} else {
|
||||||
|
Caching.getCacheManager().<BillingCacheKey, PaginationResult>getCache(DeviceManagementConstants.BILLING_CACHE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Geofence caching according to the configurations proviced by cdm-config.xml
|
* Enable Geofence caching according to the configurations proviced by cdm-config.xml
|
||||||
*/
|
*/
|
||||||
@ -711,6 +755,28 @@ public final class DeviceManagerUtil {
|
|||||||
return deviceCache;
|
return deviceCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get billing cache object
|
||||||
|
* @return {@link Cache<BillingCacheKey, PaginationResult>}
|
||||||
|
*/
|
||||||
|
public static Cache<BillingCacheKey, PaginationResult> getBillingCache() {
|
||||||
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
CacheManager manager = getCacheManager();
|
||||||
|
Cache<BillingCacheKey, PaginationResult> billingCache = null;
|
||||||
|
if (config.getBillingCacheConfiguration().isEnabled()) {
|
||||||
|
if(!isBillingCacheInitialized) {
|
||||||
|
initializeBillingCache();
|
||||||
|
}
|
||||||
|
if (manager != null) {
|
||||||
|
billingCache = manager.getCache(DeviceManagementConstants.BILLING_CACHE);
|
||||||
|
} else {
|
||||||
|
billingCache = Caching.getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER)
|
||||||
|
.getCache(DeviceManagementConstants.BILLING_CACHE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return billingCache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get geofence cache object
|
* Get geofence cache object
|
||||||
* @return {@link Cache<GeoCacheKey, GeofenceData>}
|
* @return {@link Cache<GeoCacheKey, GeofenceData>}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.apache.http.entity.StringEntity;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException;
|
import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -39,6 +40,7 @@ public class HttpReportingUtil {
|
|||||||
private static final String TRACKER_SERVER_URI = "trackerServer";
|
private static final String TRACKER_SERVER_URI = "trackerServer";
|
||||||
private static final String TRACKER_PASSWORD = "trackerPassword";
|
private static final String TRACKER_PASSWORD = "trackerPassword";
|
||||||
private static final String TRACKER_USER = "trackerUsername";
|
private static final String TRACKER_USER = "trackerUsername";
|
||||||
|
private static final String TRACKER_CONFIG = "locationPublishing";
|
||||||
|
|
||||||
public static String getReportingHost() {
|
public static String getReportingHost() {
|
||||||
return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST);
|
return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST);
|
||||||
@ -63,47 +65,49 @@ public class HttpReportingUtil {
|
|||||||
public static boolean isPublishingEnabledForTenant() {
|
public static boolean isPublishingEnabledForTenant() {
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED);
|
Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED);
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
return Boolean.valueOf(configuration.toString());
|
return Boolean.parseBoolean(configuration.toString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLocationPublishing() {
|
public static boolean isLocationPublishing() {
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(IS_LOCATION_PUBLISHING_ENABLED);
|
return getTrackerBooleanValues(IS_LOCATION_PUBLISHING_ENABLED);
|
||||||
if (configuration != null) {
|
|
||||||
return Boolean.valueOf(configuration.toString());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTrackerEnabled() {
|
public static boolean isTrackerEnabled() {
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(IS_TRACKER_ENABLED);
|
return getTrackerBooleanValues(IS_TRACKER_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String trackerServer() {
|
||||||
|
return getTrackerStringValues(TRACKER_SERVER_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String trackerPassword() {
|
||||||
|
return getTrackerStringValues(TRACKER_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String trackerUser() {
|
||||||
|
return getTrackerStringValues(TRACKER_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getTrackerBooleanValues(String trackerConfigKey) {
|
||||||
|
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_CONFIG);
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
return Boolean.valueOf(configuration.toString());
|
JSONObject locationConfig = new JSONObject(configuration.toString());
|
||||||
|
if (locationConfig.has(trackerConfigKey)) {
|
||||||
|
return Boolean.parseBoolean(locationConfig.get(trackerConfigKey).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String trackerServer() {
|
public static String getTrackerStringValues(String trackerConfigKey) {
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_SERVER_URI);
|
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_CONFIG);
|
||||||
if (configuration != null) {
|
if (configuration != null) {
|
||||||
return configuration.toString();
|
JSONObject locationConfig = new JSONObject(configuration.toString());
|
||||||
|
if (locationConfig.has(trackerConfigKey)) {
|
||||||
|
return locationConfig.get(trackerConfigKey).toString();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String trackerPassword() {
|
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_PASSWORD);
|
|
||||||
if (configuration != null) {
|
|
||||||
return configuration.toString();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String trackerUser() {
|
|
||||||
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_USER);
|
|
||||||
if (configuration != null) {
|
|
||||||
return configuration.toString();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,7 +94,6 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
LAST_BILLED_DATE BIGINT DEFAULT 0,
|
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
@ -564,16 +563,6 @@ ORDER BY TENANT_ID, DEVICE_ID;
|
|||||||
|
|
||||||
-- END OF DASHBOARD RELATED VIEWS --
|
-- END OF DASHBOARD RELATED VIEWS --
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_BILLING (
|
|
||||||
INVOICE_ID INTEGER AUTO_INCREMENT NOT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
|
||||||
DEVICE_ID INTEGER DEFAULT NULL,
|
|
||||||
BILLING_START TIMESTAMP NOT NULL,
|
|
||||||
BILLING_END TIMESTAMP NOT NULL,
|
|
||||||
PRIMARY KEY (INVOICE_ID),
|
|
||||||
CONSTRAINT fk_DM_BILLING_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
|
|
||||||
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
-- DM_EXT_GROUP_MAPPING TABLE--
|
-- DM_EXT_GROUP_MAPPING TABLE--
|
||||||
CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING (
|
CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>carbon-devicemgt</artifactId>
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
<version>5.0.14-SNAPSHOT</version>
|
<version>5.0.16-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user