forked from community/device-mgt-core
Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core
commit
d4c3af5d12
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common;
|
||||
|
||||
public class DepConfig {
|
||||
|
||||
private String agentPackageName;
|
||||
private String consumerKey;
|
||||
private String consumerSecret;
|
||||
private String accessToken;
|
||||
private String accessSecret;
|
||||
private String accessTokenExpiry;
|
||||
private String vppToken;
|
||||
|
||||
public String getAgentPackageName() {
|
||||
return agentPackageName;
|
||||
}
|
||||
|
||||
public void setAgentPackageName(String agentPackageName) {
|
||||
this.agentPackageName = agentPackageName;
|
||||
}
|
||||
|
||||
public String getConsumerKey() {
|
||||
return consumerKey;
|
||||
}
|
||||
|
||||
public void setConsumerKey(String consumerKey) {
|
||||
this.consumerKey = consumerKey;
|
||||
}
|
||||
|
||||
public String getConsumerSecret() {
|
||||
return consumerSecret;
|
||||
}
|
||||
|
||||
public void setConsumerSecret(String consumerSecret) {
|
||||
this.consumerSecret = consumerSecret;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public String getVppToken() {
|
||||
return vppToken;
|
||||
}
|
||||
|
||||
public void setVppToken(String vppToken) {
|
||||
this.vppToken = vppToken;
|
||||
}
|
||||
|
||||
public String getAccessSecret() {
|
||||
return accessSecret;
|
||||
}
|
||||
|
||||
public void setAccessSecret(String accessSecret) {
|
||||
this.accessSecret = accessSecret;
|
||||
}
|
||||
|
||||
public String getAccessTokenExpiry() {
|
||||
return accessTokenExpiry;
|
||||
}
|
||||
|
||||
public void setAccessTokenExpiry(String accessTokenExpiry) {
|
||||
this.accessTokenExpiry = accessTokenExpiry;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class ItuneAppDTO {
|
||||
int id;
|
||||
String packageName;
|
||||
String version;
|
||||
String description;
|
||||
String title;
|
||||
String paymentMethod;
|
||||
String iconURL;
|
||||
String category;
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getIconURL() {
|
||||
return iconURL;
|
||||
}
|
||||
|
||||
public void setIconURL(String iconURL) {
|
||||
this.iconURL = iconURL;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getPaymentMethod() {
|
||||
return paymentMethod;
|
||||
}
|
||||
|
||||
public void setPaymentMethod(String paymentMethod) {
|
||||
this.paymentMethod = paymentMethod;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class ProxyResponse {
|
||||
|
||||
private int code;
|
||||
private String data;
|
||||
private String executorResponse;
|
||||
|
||||
public int getCode() { return code; }
|
||||
|
||||
public void setCode(int code) { this.code = code; }
|
||||
|
||||
public String getData() { return data; }
|
||||
|
||||
public void setData(String data) { this.data = data; }
|
||||
|
||||
public String getExecutorResponse() { return executorResponse; }
|
||||
|
||||
public void setExecutorResponse(String executorResponse) { this.executorResponse = executorResponse; }
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class VppAssetDTO extends VppItuneAssetDTO {
|
||||
int id;
|
||||
int appId;
|
||||
int tenantId;
|
||||
String createdTime;
|
||||
String lastUpdatedTime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(int appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
public void setCreatedTime(String createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
public String getLastUpdatedTime() {
|
||||
return lastUpdatedTime;
|
||||
}
|
||||
|
||||
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||
this.lastUpdatedTime = lastUpdatedTime;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class VppAssociationDTO {
|
||||
int id;
|
||||
String adamId;
|
||||
String clientUserId;
|
||||
String pricingParam;
|
||||
String associationType;
|
||||
|
||||
int assetId;
|
||||
int clientId;
|
||||
int tenantId;
|
||||
String createdTime;
|
||||
String lastUpdatedTime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAdamId() {
|
||||
return adamId;
|
||||
}
|
||||
|
||||
public void setAdamId(String adamId) {
|
||||
this.adamId = adamId;
|
||||
}
|
||||
|
||||
public String getClientUserId() {
|
||||
return clientUserId;
|
||||
}
|
||||
|
||||
public void setClientUserId(String clientUserId) {
|
||||
this.clientUserId = clientUserId;
|
||||
}
|
||||
|
||||
public String getPricingParam() {
|
||||
return pricingParam;
|
||||
}
|
||||
|
||||
public void setPricingParam(String pricingParam) {
|
||||
this.pricingParam = pricingParam;
|
||||
}
|
||||
|
||||
public String getAssociationType() {
|
||||
return associationType;
|
||||
}
|
||||
|
||||
public void setAssociationType(String associationType) {
|
||||
this.associationType = associationType;
|
||||
}
|
||||
|
||||
public int getAssetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public void setAssetId(int assetId) {
|
||||
this.assetId = assetId;
|
||||
}
|
||||
|
||||
public int getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(int clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
public void setCreatedTime(String createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
public String getLastUpdatedTime() {
|
||||
return lastUpdatedTime;
|
||||
}
|
||||
|
||||
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||
this.lastUpdatedTime = lastUpdatedTime;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 String LicenseString ); 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
|
||||
* String AS ISString BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VppItuneAssetDTO {
|
||||
|
||||
|
||||
String adamId;
|
||||
String assignedCount;
|
||||
String availableCount;
|
||||
String deviceAssignable;
|
||||
String pricingParam;
|
||||
String productType;
|
||||
String retiredCount;
|
||||
String revocable;
|
||||
|
||||
List<String> supportedPlatforms;
|
||||
|
||||
public List<String> getSupportedPlatforms() {
|
||||
return supportedPlatforms;
|
||||
}
|
||||
|
||||
public void setSupportedPlatforms(List<String> supportedPlatforms) {
|
||||
this.supportedPlatforms = supportedPlatforms;
|
||||
}
|
||||
|
||||
public String getAdamId() {
|
||||
return adamId;
|
||||
}
|
||||
|
||||
public void setAdamId(String adamId) {
|
||||
this.adamId = adamId;
|
||||
}
|
||||
|
||||
public String getAssignedCount() {
|
||||
return assignedCount;
|
||||
}
|
||||
|
||||
public void setAssignedCount(String assignedCount) {
|
||||
this.assignedCount = assignedCount;
|
||||
}
|
||||
|
||||
public String getAvailableCount() {
|
||||
return availableCount;
|
||||
}
|
||||
|
||||
public void setAvailableCount(String availableCount) {
|
||||
this.availableCount = availableCount;
|
||||
}
|
||||
|
||||
public String getDeviceAssignable() {
|
||||
return deviceAssignable;
|
||||
}
|
||||
|
||||
public void setDeviceAssignable(String deviceAssignable) {
|
||||
this.deviceAssignable = deviceAssignable;
|
||||
}
|
||||
|
||||
public String getPricingParam() {
|
||||
return pricingParam;
|
||||
}
|
||||
|
||||
public void setPricingParam(String pricingParam) {
|
||||
this.pricingParam = pricingParam;
|
||||
}
|
||||
|
||||
public String getProductType() {
|
||||
return productType;
|
||||
}
|
||||
|
||||
public void setProductType(String productType) {
|
||||
this.productType = productType;
|
||||
}
|
||||
|
||||
public String getRetiredCount() {
|
||||
return retiredCount;
|
||||
}
|
||||
|
||||
public void setRetiredCount(String retiredCount) {
|
||||
this.retiredCount = retiredCount;
|
||||
}
|
||||
|
||||
public String getRevocable() {
|
||||
return revocable;
|
||||
}
|
||||
|
||||
public void setRevocable(String revocable) {
|
||||
this.revocable = revocable;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class VppItuneUserDTO {
|
||||
String clientUserId;
|
||||
String inviteCode;
|
||||
String status;
|
||||
String email;
|
||||
String managedId;
|
||||
|
||||
public String getClientUserId() {
|
||||
return clientUserId;
|
||||
}
|
||||
|
||||
public void setClientUserId(String clientUserId) {
|
||||
this.clientUserId = clientUserId;
|
||||
}
|
||||
|
||||
public String getInviteCode() {
|
||||
return inviteCode;
|
||||
}
|
||||
|
||||
public void setInviteCode(String inviteCode) {
|
||||
this.inviteCode = inviteCode;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getManagedId() {
|
||||
return managedId;
|
||||
}
|
||||
|
||||
public void setManagedId(String managedId) {
|
||||
this.managedId = managedId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class VppPaginationDTO {
|
||||
|
||||
int currentPageIndex;
|
||||
int size;
|
||||
String tokenExpirationDate;
|
||||
int nextPageIndex;
|
||||
int totalPages;
|
||||
String uId;
|
||||
String versionId;
|
||||
|
||||
public int getCurrentPageIndex() {
|
||||
return currentPageIndex;
|
||||
}
|
||||
|
||||
public void setCurrentPageIndex(int currentPageIndex) {
|
||||
this.currentPageIndex = currentPageIndex;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getTokenExpirationDate() {
|
||||
return tokenExpirationDate;
|
||||
}
|
||||
|
||||
public void setTokenExpirationDate(String tokenExpirationDate) {
|
||||
this.tokenExpirationDate = tokenExpirationDate;
|
||||
}
|
||||
|
||||
public int getNextPageIndex() {
|
||||
return nextPageIndex;
|
||||
}
|
||||
|
||||
public void setNextPageIndex(int nextPageIndex) {
|
||||
this.nextPageIndex = nextPageIndex;
|
||||
}
|
||||
|
||||
public int getTotalPages() {
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public void setTotalPages(int totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
|
||||
public String getuId() {
|
||||
return uId;
|
||||
}
|
||||
|
||||
public void setuId(String uId) {
|
||||
this.uId = uId;
|
||||
}
|
||||
|
||||
public String getVersionId() {
|
||||
return versionId;
|
||||
}
|
||||
|
||||
public void setVersionId(String versionId) {
|
||||
this.versionId = versionId;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||
|
||||
public class VppUserDTO extends VppItuneUserDTO {
|
||||
int id;
|
||||
String dmUsername;
|
||||
int tenantId;
|
||||
String createdTime;
|
||||
String lastUpdatedTime;
|
||||
String tmpPassword;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDmUsername() {
|
||||
return dmUsername;
|
||||
}
|
||||
|
||||
public void setDmUsername(String dmUsername) {
|
||||
this.dmUsername = dmUsername;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
public void setCreatedTime(String createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
public String getLastUpdatedTime() {
|
||||
return lastUpdatedTime;
|
||||
}
|
||||
|
||||
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||
this.lastUpdatedTime = lastUpdatedTime;
|
||||
}
|
||||
|
||||
public String getTmpPassword() {
|
||||
return tmpPassword;
|
||||
}
|
||||
|
||||
public void setTmpPassword(String tmpPassword) {
|
||||
this.tmpPassword = tmpPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VppUserDTO{" +
|
||||
"id=" + id +
|
||||
", dmUsername='" + dmUsername + '\'' +
|
||||
", tenantId=" + tenantId +
|
||||
", createdTime='" + createdTime + '\'' +
|
||||
", lastUpdatedTime='" + lastUpdatedTime + '\'' +
|
||||
", tmpPassword='" + tmpPassword + '\'' +
|
||||
", clientUserId='" + clientUserId + '\'' +
|
||||
", inviteCode='" + inviteCode + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", managedId='" + managedId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.services;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface VPPApplicationManager {
|
||||
|
||||
VppUserDTO addUser(VppUserDTO userDTO) throws ApplicationManagementException;
|
||||
|
||||
VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementException;
|
||||
|
||||
void updateUser(VppUserDTO userDTO) throws ApplicationManagementException;
|
||||
|
||||
void syncUsers(String clientId) throws ApplicationManagementException;
|
||||
|
||||
void syncAssets(int nextPageIndex) throws ApplicationManagementException;
|
||||
|
||||
VppAssetDTO getAssetByAppId(int appId) throws ApplicationManagementException;
|
||||
|
||||
ProxyResponse callVPPBackend(String url, String payload, String accessToken, String method) throws IOException;
|
||||
|
||||
boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
|
||||
ApplicationManagementException;
|
||||
|
||||
VppAssociationDTO getAssociation(int assetId, int userId) throws ApplicationManagementException;
|
||||
|
||||
VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws ApplicationManagementException;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VppAssociateRequestWrapper {
|
||||
|
||||
List<VppItuneAssetDTO> assets;
|
||||
List<String> clientUserIds;
|
||||
|
||||
public List<VppItuneAssetDTO> getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
public void setAssets(List<VppItuneAssetDTO> assets) {
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
public List<String> getClientUserIds() {
|
||||
return clientUserIds;
|
||||
}
|
||||
|
||||
public void setClientUserIds(List<String> clientUserIds) {
|
||||
this.clientUserIds = clientUserIds;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppPaginationDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VppItuneAssetResponseWrapper extends VppPaginationDTO {
|
||||
|
||||
List<VppAssetDTO> assets;
|
||||
|
||||
public List<VppAssetDTO> getAssets() {
|
||||
return assets;
|
||||
}
|
||||
|
||||
public void setAssets(List<VppAssetDTO> assets) {
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VppItuneUserRequestWrapper {
|
||||
|
||||
List<VppItuneUserDTO> users;
|
||||
|
||||
public VppItuneUserRequestWrapper() {
|
||||
users = new ArrayList<>();
|
||||
}
|
||||
public List<VppItuneUserDTO> getUser() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUser(List<VppItuneUserDTO> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppPaginationDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VppItuneUserResponseWrapper extends VppPaginationDTO {
|
||||
|
||||
List<VppItuneUserDTO> users;
|
||||
|
||||
public VppItuneUserResponseWrapper() {
|
||||
users = new ArrayList<>();
|
||||
}
|
||||
public List<VppItuneUserDTO> getUser() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUser(List<VppItuneUserDTO> users) {
|
||||
this.users = users;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.dao;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
|
||||
|
||||
public interface VppApplicationDAO {
|
||||
|
||||
int addVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppUserDTO getUserByDMUsername(String emmUsername, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppAssetDTO getAssetByAppId(int appId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
int addAsset(VppAssetDTO vppAssetDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppAssociationDTO getAssociation(int assetId, int userId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
int addAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppAssociationDTO updateAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
}
|
@ -0,0 +1,508 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements VppApplicationDAO {
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_VPP_USER("
|
||||
+ "CLIENT_USER_ID, "
|
||||
+ "DM_USERNAME, "
|
||||
+ "TENANT_ID, "
|
||||
+ "EMAIL, "
|
||||
+ "INVITE_CODE, "
|
||||
+ "STATUS,"
|
||||
+ "CREATED_TIME,"
|
||||
+ "LAST_UPDATED_TIME,"
|
||||
+ "MANAGED_ID,"
|
||||
+ "TEMP_PASSWORD) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
stmt.setLong(7, currentTime);
|
||||
stmt.setLong(8, currentTime);
|
||||
stmt.setString(9, userDTO.getManagedId());
|
||||
stmt.setString(10, userDTO.getTmpPassword());
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
vppUserId = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
return vppUserId;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
|
||||
String sql = "UPDATE AP_VPP_USER SET ";
|
||||
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
|
||||
sql += "CLIENT_USER_ID = ?,";
|
||||
}
|
||||
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
|
||||
sql += "DM_USERNAME = ?,";
|
||||
}
|
||||
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
|
||||
sql += "EMAIL = ?,";
|
||||
}
|
||||
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
|
||||
sql += "INVITE_CODE = ?,";
|
||||
}
|
||||
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
|
||||
sql += "STATUS = ?,";
|
||||
}
|
||||
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
|
||||
sql += "MANAGED_ID = ?,";
|
||||
}
|
||||
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
|
||||
sql += "TEMP_PASSWORD = ?,";
|
||||
}
|
||||
|
||||
sql += " TENANT_ID = ?, LAST_UPDATED_TIME = ? WHERE ID = ?";
|
||||
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
long updatedTime = System.currentTimeMillis();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int x = 0;
|
||||
|
||||
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getClientUserId());
|
||||
}
|
||||
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getDmUsername());
|
||||
}
|
||||
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getEmail());
|
||||
}
|
||||
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getInviteCode());
|
||||
}
|
||||
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getStatus());
|
||||
}
|
||||
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getManagedId());
|
||||
}
|
||||
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
|
||||
stmt.setString(++x, userDTO.getTmpPassword());
|
||||
}
|
||||
stmt.setInt(++x, tenantId);
|
||||
stmt.setLong(++x, updatedTime);
|
||||
stmt.setInt(++x, userDTO.getId());
|
||||
if (stmt.executeUpdate() == 1) {
|
||||
return userDTO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppUserDTO getUserByDMUsername(String emmUsername, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT "
|
||||
+ "ID, "
|
||||
+ "CLIENT_USER_ID, "
|
||||
+ "TENANT_ID, "
|
||||
+ "EMAIL, "
|
||||
+ "INVITE_CODE, "
|
||||
+ "STATUS, "
|
||||
+ "CREATED_TIME, "
|
||||
+ "LAST_UPDATED_TIME, "
|
||||
+ "MANAGED_ID, "
|
||||
+ "TEMP_PASSWORD, "
|
||||
+ "DM_USERNAME "
|
||||
+ "FROM AP_VPP_USER "
|
||||
+ "WHERE DM_USERNAME = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, emmUsername);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
return DAOUtil.loadVppUser(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when retrieving vpp user by EMM Username.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to retrieve vpp user by EMM Username.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one user for: " + emmUsername;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssetDTO getAssetByAppId(int appId, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT "
|
||||
+ "ID, "
|
||||
+ "APP_ID, "
|
||||
+ "TENANT_ID, "
|
||||
+ "CREATED_TIME, "
|
||||
+ "LAST_UPDATED_TIME, "
|
||||
+ "ADAM_ID, "
|
||||
+ "ASSIGNED_COUNT, "
|
||||
+ "DEVICE_ASSIGNABLE, "
|
||||
+ "PRICING_PARAMS, "
|
||||
+ "PRODUCT_TYPE, "
|
||||
+ "RETIRED_COUNT, "
|
||||
+ "REVOCABLE "
|
||||
// + "SUPPORTED_PLATFORMS "
|
||||
+ "FROM AP_ASSETS "
|
||||
+ "WHERE APP_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, appId);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
return DAOUtil.loadAsset(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when retrieving asset data of app id "+ appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to retrieve asset by app id.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one app for app id: " + appId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addAsset(VppAssetDTO vppAssetDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int assetId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_ASSETS("
|
||||
+ "APP_ID, "
|
||||
+ "TENANT_ID, "
|
||||
+ "CREATED_TIME,"
|
||||
+ "LAST_UPDATED_TIME,"
|
||||
+ "ADAM_ID,"
|
||||
+ "ASSIGNED_COUNT,"
|
||||
+ "DEVICE_ASSIGNABLE,"
|
||||
+ "PRICING_PARAMS,"
|
||||
+ "PRODUCT_TYPE,"
|
||||
+ "RETIRED_COUNT,"
|
||||
+ "REVOCABLE, "
|
||||
+ "SUPPORTED_PLATFORMS) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setInt(1, vppAssetDTO.getAppId());
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setLong(3, currentTime);
|
||||
stmt.setLong(4, currentTime);
|
||||
stmt.setString(5, vppAssetDTO.getAdamId());
|
||||
stmt.setString(6, vppAssetDTO.getAssignedCount());
|
||||
stmt.setString(7, vppAssetDTO.getDeviceAssignable());
|
||||
stmt.setString(8, vppAssetDTO.getPricingParam());
|
||||
stmt.setString(9, vppAssetDTO.getProductType());
|
||||
stmt.setString(10, vppAssetDTO.getRetiredCount());
|
||||
stmt.setString(11, vppAssetDTO.getRevocable());
|
||||
List<String> platformList = vppAssetDTO.getSupportedPlatforms();
|
||||
String platformString = String.join(",", platformList);
|
||||
stmt.setString(12, platformString);
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
assetId = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
return assetId;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when adding the asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to add the asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
|
||||
String sql = "UPDATE AP_ASSETS SET ";
|
||||
|
||||
if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
|
||||
sql += "ADAM_ID = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
|
||||
sql += "ASSIGNED_COUNT = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
|
||||
sql += "DEVICE_ASSIGNABLE = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
|
||||
sql += "PRICING_PARAMS = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
|
||||
sql += "PRODUCT_TYPE = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
|
||||
sql += "RETIRED_COUNT = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
|
||||
sql += "REVOCABLE = ?, ";
|
||||
}
|
||||
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
|
||||
sql += "SUPPORTED_PLATFORMS = ?,";
|
||||
}
|
||||
sql += "APP_ID = ?, LAST_UPDATED_TIME = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
long updatedTime = System.currentTimeMillis();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int x = 0;
|
||||
|
||||
if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getAdamId());
|
||||
}
|
||||
if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getAssignedCount());
|
||||
}
|
||||
if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getDeviceAssignable());
|
||||
}
|
||||
if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getPricingParam());
|
||||
}
|
||||
if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getProductType());
|
||||
}
|
||||
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getRetiredCount());
|
||||
}
|
||||
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
|
||||
stmt.setString(++x, vppAssetDTO.getRevocable());
|
||||
}
|
||||
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
|
||||
List<String> platformList = vppAssetDTO.getSupportedPlatforms();
|
||||
String platformString = String.join(",", platformList);
|
||||
stmt.setString(++x, platformString);
|
||||
}
|
||||
|
||||
stmt.setInt(++x, vppAssetDTO.getAppId());
|
||||
stmt.setLong(++x, updatedTime);
|
||||
stmt.setInt(++x, vppAssetDTO.getId());
|
||||
stmt.setLong(++x, tenantId);
|
||||
if (stmt.executeUpdate() == 1) {
|
||||
return vppAssetDTO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssociationDTO getAssociation(int assetId, int userId, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT "
|
||||
+ "ID, "
|
||||
+ "ASSOCIATION_TYPE, "
|
||||
+ "CREATED_TIME, "
|
||||
+ "LAST_UPDATED_TIME, "
|
||||
+ "PRICING_PARAMS "
|
||||
+ "FROM AP_VPP_ASSOCIATION "
|
||||
+ "WHERE ASSET_ID = ? AND USER_ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, assetId);
|
||||
stmt.setInt(2, userId);
|
||||
stmt.setInt(3, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
return DAOUtil.loadAssignment(rs);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when retrieving assignment data of user with id "+ userId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to retrieve assignment by asset id and user id.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Found more than one assignment for user id: " + userId + " and asset id: " + assetId;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addAssociation(VppAssociationDTO vppAssociationDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int associationId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_VPP_ASSOCIATION("
|
||||
+ "ASSET_ID, "
|
||||
+ "USER_ID, "
|
||||
+ "TENANT_ID, "
|
||||
+ "ASSOCIATION_TYPE,"
|
||||
+ "CREATED_TIME,"
|
||||
+ "LAST_UPDATED_TIME,"
|
||||
+ "PRICING_PARAMS) "
|
||||
+ "VALUES (?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setInt(1, vppAssociationDTO.getAssetId());
|
||||
stmt.setInt(2, vppAssociationDTO.getClientId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, vppAssociationDTO.getAssociationType());
|
||||
stmt.setLong(5, currentTime);
|
||||
stmt.setLong(6, currentTime);
|
||||
stmt.setString(7, vppAssociationDTO.getPricingParam());
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
associationId = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
return associationId;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when adding the asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to add the asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssociationDTO updateAssociation(VppAssociationDTO vppAssociationDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
|
||||
String sql = "UPDATE "
|
||||
+ "AP_VPP_ASSOCIATION "
|
||||
+ "SET "
|
||||
+ "ASSET_ID = ?,"
|
||||
+ "USER_ID = ?, "
|
||||
+ "ASSOCIATION_TYPE = ?, "
|
||||
+ "LAST_UPDATED_TIME = ?, "
|
||||
+ "PRICING_PARAMS = ? "
|
||||
+ "WHERE ID = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
long updatedTime = System.currentTimeMillis();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, vppAssociationDTO.getAssetId());
|
||||
stmt.setInt(2, vppAssociationDTO.getClientId());
|
||||
stmt.setString(3, vppAssociationDTO.getAssociationType());
|
||||
stmt.setLong(4, updatedTime);
|
||||
stmt.setString(5, vppAssociationDTO.getPricingParam());
|
||||
stmt.setInt(6, vppAssociationDTO.getId());
|
||||
stmt.setLong(7, tenantId);
|
||||
if (stmt.executeUpdate() == 1) {
|
||||
return vppAssociationDTO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class OracleVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_VPP_USER("
|
||||
+ "CLIENT_USER_ID, "
|
||||
+ "DM_USERNAME, "
|
||||
+ "TENANT_ID, "
|
||||
+ "EMAIL, "
|
||||
+ "INVITE_CODE, "
|
||||
+ "STATUS,"
|
||||
+ "CREATED_TIME,"
|
||||
+ "LAST_UPDATED_TIME,"
|
||||
+ "MANAGED_ID,"
|
||||
+ "TEMP_PASSWORD) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[] {"ID"})) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
stmt.setLong(7, currentTime);
|
||||
stmt.setLong(8, currentTime);
|
||||
stmt.setString(9, userDTO.getManagedId());
|
||||
stmt.setString(10, userDTO.getTmpPassword());
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
vppUserId = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
return vppUserId;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class PostgreSQLVppApplicationDAO extends GenericVppApplicationDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_VPP_USER("
|
||||
+ "CLIENT_USER_ID, "
|
||||
+ "DM_USERNAME, "
|
||||
+ "TENANT_ID, "
|
||||
+ "EMAIL, "
|
||||
+ "INVITE_CODE, "
|
||||
+ "STATUS,"
|
||||
+ "CREATED_TIME,"
|
||||
+ "LAST_UPDATED_TIME,"
|
||||
+ "MANAGED_ID,"
|
||||
+ "TEMP_PASSWORD) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
stmt.setLong(7, currentTime);
|
||||
stmt.setLong(8, currentTime);
|
||||
stmt.setString(9, userDTO.getManagedId());
|
||||
stmt.setString(10, userDTO.getTmpPassword());
|
||||
stmt.executeUpdate();
|
||||
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||
if (rs.next()) {
|
||||
vppUserId = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
return vppUserId;
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
public class SQLServerVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||
}
|
@ -0,0 +1,610 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.DepConfig;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ItuneAppDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.exception.TransactionManagementException;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppAssociateRequestWrapper;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneAssetResponseWrapper;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneUserRequestWrapper;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneUserResponseWrapper;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.VisibilityDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.VppHttpUtil;
|
||||
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
||||
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
|
||||
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
private static final String APP_API = "https://vpp.itunes.apple.com/mdm/v2";
|
||||
private static final String ASSETS = APP_API + "/assets";
|
||||
private static final String USER_CREATE = APP_API + "/users/create";
|
||||
private static final String USER_UPDATE = APP_API + "/users/update";
|
||||
private static final String USER_GET = APP_API + "/users";
|
||||
private static final String ASSIGNMENTS_POST = APP_API + "/assets/associate";
|
||||
private static final String ASSIGNMENTS_GET = APP_API + "/assignments";
|
||||
private static final String TOKEN = "";
|
||||
private static final String LOOKUP_API = "https://uclient-api.itunes.apple" +
|
||||
".com/WebObjects/MZStorePlatform.woa/wa/lookup?version=2&id=";
|
||||
private static final String LOOKUP_API_PREFIX =
|
||||
"&p=mdm-lockup&caller=MDM&platform=enterprisestore&cc=us&l=en";
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(VppApplicationManagerImpl.class);
|
||||
|
||||
private ApplicationDAO applicationDAO;
|
||||
private SPApplicationDAO spApplicationDAO;
|
||||
private VisibilityDAO visibilityDAO;
|
||||
private final LifecycleStateManager lifecycleStateManager;
|
||||
private VppApplicationDAO vppApplicationDAO;
|
||||
|
||||
public VppApplicationManagerImpl() {
|
||||
initDataAccessObjects();
|
||||
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||
}
|
||||
|
||||
private void initDataAccessObjects() {
|
||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
|
||||
this.spApplicationDAO = ApplicationManagementDAOFactory.getSPApplicationDAO();
|
||||
this.vppApplicationDAO = ApplicationManagementDAOFactory.getVppApplicationDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppUserDTO addUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
|
||||
// Call the API to add
|
||||
try {
|
||||
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||
VppItuneUserRequestWrapper wrapper = new VppItuneUserRequestWrapper();
|
||||
wrapper.getUser().add(ituneUserDTO);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String userPayload = gson.toJson(wrapper);
|
||||
|
||||
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, getVppToken(), Constants.VPP.POST);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||
// Create user does not return any useful data. Its needed to call the backend again
|
||||
ProxyResponse getUserResponse = callVPPBackend(USER_GET + Constants.VPP.CLIENT_USER_ID_PARAM +
|
||||
userDTO.getClientUserId(), userPayload, getVppToken(), Constants.VPP.GET);
|
||||
if ((getUserResponse.getCode() == HttpStatus.SC_OK || getUserResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && getUserResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||
VppItuneUserResponseWrapper vppItuneUserResponseWrapper = gson.fromJson
|
||||
(getUserResponse.getData(), VppItuneUserResponseWrapper.class);
|
||||
userDTO.setInviteCode(vppItuneUserResponseWrapper.getUser().get(0)
|
||||
.getInviteCode());
|
||||
userDTO.setStatus(vppItuneUserResponseWrapper.getUser().get(0).getStatus());
|
||||
log.error("userDTO " + userDTO.toString());
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
int id = vppApplicationDAO.addVppUser(userDTO, tenantId);
|
||||
if (id != -1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
userDTO.setId(id);
|
||||
userDTO.setTenantId(PrivilegedCarbonContext
|
||||
.getThreadLocalCarbonContext().getTenantId());
|
||||
return userDTO;
|
||||
}
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
return null;
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding the Vpp User.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for adding Vpp User.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for adding Vpp User.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while calling VPP backend to add user";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return vppApplicationDAO.getUserByDMUsername(emmUsername, tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "DB Connection error occurs while getting vpp User data related to EMM user " + emmUsername + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while getting vpp User data related to EMM user " + emmUsername + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||
VppItuneUserRequestWrapper wrapper = new VppItuneUserRequestWrapper();
|
||||
wrapper.getUser().add(ituneUserDTO);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String userPayload = gson.toJson(wrapper);
|
||||
try {
|
||||
ProxyResponse proxyResponse = callVPPBackend(USER_UPDATE, userPayload, getVppToken(), Constants.VPP.POST);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||
VppUserDTO currentUserDTO = getUserByDMUsername(userDTO.getDmUsername());
|
||||
if (currentUserDTO != null) {
|
||||
userDTO.setId(currentUserDTO.getId());
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.updateVppUser(userDTO, tenantId) == null) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Unable to update the Vpp user " +userDTO.getId();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while updating the Vpp User.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for Vpp User update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for Vpp User update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while calling VPP backend to update";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncUsers(String clientId) throws ApplicationManagementException {
|
||||
ProxyResponse proxyResponse = null;
|
||||
try {
|
||||
proxyResponse = callVPPBackend(USER_GET, null, getVppToken(), Constants
|
||||
.VPP.GET);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||
log.error("proxyResponse " + proxyResponse.getData());
|
||||
Gson gson = new Gson();
|
||||
VppItuneUserResponseWrapper vppUserResponseWrapper = gson.fromJson
|
||||
(proxyResponse.getData(), VppItuneUserResponseWrapper.class);
|
||||
// TODO: to implement later
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while syncing VPP users with backend";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAssets(int nextPageIndex) throws ApplicationManagementException {
|
||||
ProxyResponse proxyResponse = null;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
String url = ASSETS;
|
||||
if (nextPageIndex > 0) { // Not the first page
|
||||
url += "?pageIndex=" + nextPageIndex;
|
||||
}
|
||||
proxyResponse = callVPPBackend(url, null, getVppToken(), Constants.VPP.GET);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||
Gson gson = new Gson();
|
||||
VppItuneAssetResponseWrapper vppItuneAssetResponse = gson.fromJson
|
||||
(proxyResponse.getData(), VppItuneAssetResponseWrapper.class);
|
||||
if (vppItuneAssetResponse.getSize() > 0) {
|
||||
for (VppAssetDTO vppAssetDTO : vppItuneAssetResponse.getAssets()) {
|
||||
vppAssetDTO.setTenantId(PrivilegedCarbonContext
|
||||
.getThreadLocalCarbonContext().getTenantId());
|
||||
vppAssetDTO.setCreatedTime(String.valueOf(System.currentTimeMillis()));
|
||||
vppAssetDTO.setLastUpdatedTime(String.valueOf(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
for (VppAssetDTO vppAssetDTO : vppItuneAssetResponse.getAssets()) {
|
||||
ItuneAppDTO ituneAppDTO = lookupAsset(vppAssetDTO.getAdamId());
|
||||
ApplicationManagementUtil.persistApp(ituneAppDTO);
|
||||
List<Application> applications = ApplicationManagementUtil.getAppDetails(vppAssetDTO.getAdamId());
|
||||
for (Application application :applications) {
|
||||
VppAssetDTO vppAssetDTOs = getAssetByAppId(application.getId());
|
||||
if (vppAssetDTOs == null) {
|
||||
vppAssetDTOs = new VppAssetDTO();
|
||||
vppAssetDTO.setAppId(application.getId());
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.addAsset(vppAssetDTO, tenantId) != -1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
}
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding the Asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for adding Asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for adding Asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
} else {
|
||||
vppAssetDTOs.setAppId(application.getId());
|
||||
vppAssetDTOs.setSupportedPlatforms(vppAssetDTO.getSupportedPlatforms());
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.updateAsset(vppAssetDTOs, tenantId) == null) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Unable to update the asset: " +vppAssetDTOs.getAdamId();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while updating the Asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for Asset update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for Asset update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vppItuneAssetResponse.getCurrentPageIndex() == (vppItuneAssetResponse
|
||||
.getTotalPages() - 1)) {
|
||||
return;
|
||||
} else {
|
||||
syncAssets(vppItuneAssetResponse.getNextPageIndex());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while syncing VPP users with backend";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private ItuneAppDTO lookupAsset(String packageName) throws ApplicationManagementException {
|
||||
String lookupURL = LOOKUP_API + packageName + LOOKUP_API_PREFIX;
|
||||
try {
|
||||
ProxyResponse proxyResponse = callVPPBackend(lookupURL, null, getVppToken(), Constants.VPP.GET);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.GET_APP_DATA_RESPONSE_START)) {
|
||||
String responseData = proxyResponse.getData();
|
||||
JsonObject responseJson = new JsonParser().parse(responseData)
|
||||
.getAsJsonObject();
|
||||
|
||||
JsonObject results = responseJson.getAsJsonObject(Constants.ApplicationProperties.RESULTS);
|
||||
JsonObject result = results.getAsJsonObject(packageName);
|
||||
|
||||
String iconUrl = result.getAsJsonObject(Constants.ApplicationProperties.ARTWORK)
|
||||
.get(Constants.ApplicationProperties.URL).getAsString();
|
||||
int lastSlashIndex = iconUrl.lastIndexOf("/");
|
||||
if (lastSlashIndex != -1) {
|
||||
iconUrl = iconUrl.substring(0, lastSlashIndex + 1) + Constants.VPP.REMOTE_FILE_NAME;
|
||||
}
|
||||
|
||||
String descriptionStandard = result.getAsJsonObject(Constants.ApplicationProperties.DESCRIPTION)
|
||||
.get(Constants.ApplicationProperties.STANDARD).getAsString();
|
||||
if (descriptionStandard != null && !descriptionStandard.isEmpty()) {
|
||||
descriptionStandard = descriptionStandard.substring(0, 199);
|
||||
}
|
||||
String name = result.get(Constants.ApplicationProperties.NAME).getAsString();
|
||||
double price = result.getAsJsonArray(Constants.ApplicationProperties.OFFERS).get(0)
|
||||
.getAsJsonObject().get(Constants.ApplicationProperties.PRICE).getAsDouble();
|
||||
String version = result.getAsJsonArray(Constants.ApplicationProperties.OFFERS)
|
||||
.get(0).getAsJsonObject().get(Constants.ApplicationProperties.VERSION)
|
||||
.getAsJsonObject().get(Constants.ApplicationProperties.DISPLAY).getAsString();
|
||||
|
||||
String[] genreNames = new Gson().fromJson(result.getAsJsonArray(Constants.ApplicationProperties.GENRE_NAMES),
|
||||
String[].class);
|
||||
|
||||
ItuneAppDTO ituneAppDTO = new ItuneAppDTO();
|
||||
ituneAppDTO.setPackageName(packageName);
|
||||
ituneAppDTO.setVersion(version);
|
||||
ituneAppDTO.setDescription(descriptionStandard);
|
||||
ituneAppDTO.setTitle(name);
|
||||
|
||||
if (Constants.ApplicationProperties.PRICE_ZERO.equalsIgnoreCase(String.valueOf(price))) {
|
||||
ituneAppDTO.setPaymentMethod(Constants.ApplicationProperties.FREE_SUB_METHOD);
|
||||
} else {
|
||||
ituneAppDTO.setPaymentMethod(Constants.ApplicationProperties.PAID_SUB_METHOD);
|
||||
}
|
||||
ituneAppDTO.setIconURL(iconUrl);
|
||||
ituneAppDTO.setCategory(genreNames[0]);
|
||||
|
||||
return ituneAppDTO;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while looking up the app details";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssetDTO getAssetByAppId(int appId) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return vppApplicationDAO.getAssetByAppId(appId, tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "DB Connection error occurs while getting asset related to app with app id " + appId + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while getting asset data related to app with app id " + appId + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
|
||||
ApplicationManagementException {
|
||||
|
||||
List<VppAssociationDTO> associations = new ArrayList<>(); // To save to UEM DBs
|
||||
List<String> clientUserIds = new ArrayList<>(); // Need this to send to vpp backend.
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
if (asset != null) {
|
||||
for (VppUserDTO vppUserDTO : vppUsers) {
|
||||
VppAssociationDTO associationDTO = VppHttpUtil.getAssociation(vppUserDTO, asset);
|
||||
associations.add(associationDTO);
|
||||
clientUserIds.add(vppUserDTO.getClientUserId());
|
||||
}
|
||||
|
||||
if (associations.size() > 0) {
|
||||
//TODO: Add or Update associations
|
||||
try {
|
||||
|
||||
// Create the VPP backend payload
|
||||
List<VppItuneAssetDTO> assets = new ArrayList<>();
|
||||
VppItuneAssetDTO assetDTO = new VppItuneAssetDTO();
|
||||
assetDTO.setAdamId(asset.getAdamId());
|
||||
assetDTO.setPricingParam(asset.getPricingParam());
|
||||
assets.add(assetDTO);
|
||||
|
||||
VppAssociateRequestWrapper vppAssociate = new VppAssociateRequestWrapper();
|
||||
vppAssociate.setAssets(assets);
|
||||
vppAssociate.setClientUserIds(clientUserIds);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String payload = gson.toJson(vppAssociate);
|
||||
|
||||
ProxyResponse proxyResponse = callVPPBackend(ASSIGNMENTS_POST, payload, getVppToken(),
|
||||
Constants.VPP.POST);
|
||||
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||
// Create assignment does not return any useful data. Its needed to call the backend again
|
||||
ProxyResponse getAssignmentResponse = callVPPBackend(ASSIGNMENTS_GET, null, getVppToken(), Constants.VPP.GET);
|
||||
if ((getAssignmentResponse.getCode() == HttpStatus.SC_OK || getAssignmentResponse.getCode() ==
|
||||
HttpStatus.SC_CREATED) && getAssignmentResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||
// VppAssociateResponseWrapper vppAssociateResponseWrapper = gson.fromJson
|
||||
// (getAssignmentResponse.getData(), VppAssociateResponseWrapper.class);
|
||||
for (VppAssociationDTO association : associations) {
|
||||
|
||||
VppAssociationDTO vppAssociation = getAssociation(association.getAssetId(), association.getClientId());
|
||||
|
||||
if (vppAssociation == null) {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.addAssociation(association, tenantId) != -1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
}
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
return false;
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding the Assignment.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for adding Assignment.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for adding Assignment.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.updateAssociation(association, tenantId) == null) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Unable to update the assignment: " +association.getAssetId();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while updating the Asset.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while executing database transaction for Asset update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while retrieving the database connection for Asset update.";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while adding associations";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VppAssociationDTO getAssociation(int assetId, int userId) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return vppApplicationDAO.getAssociation(assetId, userId, tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "DB Connection error occurs while getting assignment related to user of id " + userId + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while getting assignment data related to user of id " + userId + ".";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyResponse callVPPBackend(String url,
|
||||
String payload,
|
||||
String accessToken,
|
||||
String method) throws IOException {
|
||||
return VppHttpUtil.execute(url, payload, accessToken, method);
|
||||
}
|
||||
|
||||
public String getVppToken() throws ApplicationManagementException {
|
||||
String token = "";
|
||||
MetadataManagementService meta = APIUtil.getMetadataManager();
|
||||
Metadata metadata = null;
|
||||
try {
|
||||
metadata = meta.retrieveMetadata("DEP_META_KEY");
|
||||
if (metadata != null) {
|
||||
|
||||
Gson g = new Gson();
|
||||
DepConfig depConfigs = g.fromJson(metadata.getMetaValue(), DepConfig.class);
|
||||
token = depConfigs.getVppToken();
|
||||
return token;
|
||||
}
|
||||
}catch (MetadataManagementException e) {
|
||||
String msg = "Error when retrieving metadata of vpp feature";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws ApplicationManagementException {
|
||||
// Todo: Join the 3 tables and find a matching association
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.application.mgt.core.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class VppHttpUtil {
|
||||
private static final Log log = LogFactory.getLog(VppHttpUtil.class);
|
||||
|
||||
public static ProxyResponse execute(String url,
|
||||
String payload,
|
||||
String accessToken,
|
||||
String method) throws IOException {
|
||||
|
||||
HttpRequestBase endpoint = null;
|
||||
if (Constants.VPP.GET.equalsIgnoreCase(method) || Constants.VPP.DELETE.equalsIgnoreCase(method)) {
|
||||
endpoint = new HttpGet(url);
|
||||
addHeaders(endpoint, accessToken);
|
||||
return VppHttpUtil.execute(endpoint);
|
||||
} else if (Constants.VPP.POST.equalsIgnoreCase(method)) {
|
||||
endpoint = new HttpPost(url);
|
||||
} else if (Constants.VPP.PUT.equalsIgnoreCase(method)) {
|
||||
endpoint = new HttpPut(url);
|
||||
}
|
||||
addHeaders(endpoint, accessToken);
|
||||
|
||||
|
||||
if (payload != null) {
|
||||
HttpEntity forwardRequestBody = new StringEntity(payload, ContentType.APPLICATION_JSON.toString(), "utf-8");
|
||||
if (Constants.VPP.POST.equalsIgnoreCase(method)) {
|
||||
((HttpPost) endpoint).setEntity(forwardRequestBody);
|
||||
} else if (Constants.VPP.PUT.equalsIgnoreCase(method)) {
|
||||
((HttpPut) endpoint).setEntity(forwardRequestBody);
|
||||
}
|
||||
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info("Forwarding request to " + url);
|
||||
}
|
||||
return VppHttpUtil.execute(endpoint);
|
||||
}
|
||||
|
||||
private static void addHeaders(HttpRequestBase endpoint, String accessToken) {
|
||||
endpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
|
||||
endpoint.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.toString());
|
||||
endpoint.setHeader(HttpHeaders.AUTHORIZATION, Constants.VPP.BEARER + accessToken);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* @param httpRequest - httpMethod e.g:- HttpPost, HttpGet
|
||||
* @return response as string
|
||||
* @throws IOException IO exception returns if error occurs when executing the httpMethod
|
||||
*/
|
||||
private static ProxyResponse execute(HttpRequestBase httpRequest) throws IOException {
|
||||
try (CloseableHttpClient client = getHttpClient()) {
|
||||
HttpResponse response = client.execute(httpRequest);
|
||||
ProxyResponse proxyResponse = new ProxyResponse();
|
||||
|
||||
if (response == null) {
|
||||
log.error("Received null response for http request : " + httpRequest.getMethod() + " " + httpRequest
|
||||
.getURI().toString());
|
||||
proxyResponse.setCode(Constants.VPP.INTERNAL_ERROR_CODE);
|
||||
proxyResponse.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(
|
||||
Constants.VPP.INTERNAL_ERROR_CODE));
|
||||
return proxyResponse;
|
||||
} else {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
String jsonString = result.toString();
|
||||
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
|
||||
proxyResponse.setCode(statusCode);
|
||||
proxyResponse.setData(jsonString);
|
||||
proxyResponse.setExecutorResponse("SUCCESS");
|
||||
return proxyResponse;
|
||||
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
|
||||
if (jsonString.contains("Access token expired") || jsonString
|
||||
.contains("Invalid input. Access token validation failed")) {
|
||||
proxyResponse.setCode(statusCode);
|
||||
proxyResponse.setExecutorResponse(Constants.VPP.TOKEN_IS_EXPIRED);
|
||||
return proxyResponse;
|
||||
} else {
|
||||
log.error(
|
||||
"Received " + statusCode + " response for http request : " + httpRequest.getMethod()
|
||||
+ " " + httpRequest.getURI().toString() + ". Error message: " + jsonString);
|
||||
proxyResponse.setCode(statusCode);
|
||||
proxyResponse.setData(jsonString);
|
||||
proxyResponse.setExecutorResponse(
|
||||
Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(statusCode));
|
||||
return proxyResponse;
|
||||
}
|
||||
}
|
||||
log.error("Received " + statusCode +
|
||||
" response for http request : " + httpRequest.getMethod() + " " + httpRequest.getURI()
|
||||
.toString() + ". Error message: " + jsonString);
|
||||
proxyResponse.setCode(statusCode);
|
||||
proxyResponse.setData(jsonString);
|
||||
proxyResponse
|
||||
.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(statusCode));
|
||||
return proxyResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param statusCode Provide status code, e.g:- 400, 401, 500 etc
|
||||
* @return relative status code key for given status code.
|
||||
*/
|
||||
public static String getStatusKey(int statusCode) {
|
||||
String statusCodeKey;
|
||||
|
||||
switch (statusCode) {
|
||||
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
|
||||
statusCodeKey = "internalServerError";
|
||||
break;
|
||||
case HttpStatus.SC_BAD_REQUEST:
|
||||
statusCodeKey = "badRequest";
|
||||
break;
|
||||
case HttpStatus.SC_UNAUTHORIZED:
|
||||
statusCodeKey = "unauthorized";
|
||||
break;
|
||||
case HttpStatus.SC_FORBIDDEN:
|
||||
statusCodeKey = "forbidden";
|
||||
break;
|
||||
case HttpStatus.SC_NOT_FOUND:
|
||||
statusCodeKey = "notFound";
|
||||
break;
|
||||
case HttpStatus.SC_METHOD_NOT_ALLOWED:
|
||||
statusCodeKey = "methodNotAllowed";
|
||||
break;
|
||||
case HttpStatus.SC_NOT_ACCEPTABLE:
|
||||
statusCodeKey = "notAcceptable";
|
||||
break;
|
||||
case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
|
||||
statusCodeKey = "unsupportedMediaType";
|
||||
break;
|
||||
default:
|
||||
statusCodeKey = "defaultPage";
|
||||
break;
|
||||
}
|
||||
return statusCodeKey;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Handle error requests.
|
||||
*
|
||||
* @param resp {@link HttpServletResponse}
|
||||
* @param proxyResponse {@link ProxyResponse}
|
||||
* @throws IOException If error occurred when trying to send the error response.
|
||||
*/
|
||||
public static void handleError(HttpServletResponse resp, ProxyResponse proxyResponse) throws IOException {
|
||||
Gson gson = new Gson();
|
||||
if (proxyResponse == null) {
|
||||
proxyResponse = new ProxyResponse();
|
||||
proxyResponse.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||
proxyResponse.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + VppHttpUtil
|
||||
.getStatusKey(Constants.VPP.INTERNAL_ERROR_CODE));
|
||||
}
|
||||
resp.setStatus(proxyResponse.getCode());
|
||||
resp.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
resp.setCharacterEncoding(Consts.UTF_8.name());
|
||||
|
||||
proxyResponse.setExecutorResponse(null);
|
||||
try (PrintWriter writer = resp.getWriter()) {
|
||||
writer.write(gson.toJson(proxyResponse));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle error requests with custom error codes.
|
||||
*
|
||||
* @param resp {@link HttpServletResponse}
|
||||
* @param errorCode HTTP error status code
|
||||
* @throws IOException If error occurred when trying to send the error response.
|
||||
*/
|
||||
public static void handleError(HttpServletResponse resp, int errorCode)
|
||||
throws IOException {
|
||||
ProxyResponse proxyResponse = new ProxyResponse();
|
||||
proxyResponse.setCode(errorCode);
|
||||
proxyResponse.setExecutorResponse(
|
||||
Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + VppHttpUtil.getStatusKey(errorCode));
|
||||
VppHttpUtil.handleError(resp, proxyResponse);
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param resp {@link HttpServletResponse}
|
||||
* Return Success Response.
|
||||
*/
|
||||
public static void handleSuccess(HttpServletResponse resp, ProxyResponse proxyResponse) throws IOException {
|
||||
if (proxyResponse == null) {
|
||||
handleError(resp, null);
|
||||
return;
|
||||
}
|
||||
resp.setStatus(proxyResponse.getCode());
|
||||
resp.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
resp.setCharacterEncoding(Consts.UTF_8.name());
|
||||
JSONObject response = new JSONObject();
|
||||
String responseData = proxyResponse.getData();
|
||||
|
||||
if (!StringUtils.isEmpty(responseData)) {
|
||||
try {
|
||||
if (responseData.startsWith("{")) {
|
||||
JSONObject responseDataJsonObj = new JSONObject(responseData);
|
||||
response.put("data", responseDataJsonObj);
|
||||
} else if (responseData.startsWith("[")) {
|
||||
JSONArray responseDataJsonArr = new JSONArray(responseData);
|
||||
response.put("data", responseDataJsonArr);
|
||||
} else {
|
||||
log.warn("Response data is not valid json string >> " + responseData);
|
||||
response.put("data", responseData);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Response data is not passable");
|
||||
response.put("data", responseData);
|
||||
}
|
||||
}
|
||||
|
||||
try (PrintWriter writer = resp.getWriter()) {
|
||||
writer.write(response.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Http client based on hostname verification.
|
||||
*
|
||||
* @return {@link CloseableHttpClient} http client
|
||||
*/
|
||||
public static CloseableHttpClient getHttpClient() {
|
||||
return HttpClients.custom().setMaxConnTotal(1).setMaxConnPerRoute(1).build();
|
||||
}
|
||||
|
||||
public static VppAssociationDTO getAssociation(VppUserDTO user, VppAssetDTO asset) {
|
||||
VppAssociationDTO associationDTO = new VppAssociationDTO();
|
||||
associationDTO.setAdamId(asset.getAdamId());
|
||||
associationDTO.setClientUserId(user.getClientUserId());
|
||||
associationDTO.setPricingParam(asset.getPricingParam());
|
||||
associationDTO.setAssociationType(Constants.ApplicationProperties.ASSOCIATION_USER);
|
||||
|
||||
associationDTO.setAssetId(asset.getId());
|
||||
associationDTO.setClientId(user.getId());
|
||||
associationDTO.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.getTenantId(true));
|
||||
associationDTO.setCreatedTime(String.valueOf(System.currentTimeMillis()));
|
||||
associationDTO.setLastUpdatedTime(String.valueOf(System.currentTimeMillis()));
|
||||
return associationDTO;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.common;
|
||||
|
||||
public class CertificatePaginationRequest {
|
||||
private int startIndex;
|
||||
private int rowCount;
|
||||
private String serialNumber;
|
||||
private String deviceIdentifier;
|
||||
private String username;
|
||||
|
||||
public CertificatePaginationRequest(int start, int rowCount) {
|
||||
this.startIndex = start;
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public void setRowCount(int rowCount) {
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public String getSerialNumber() {
|
||||
return serialNumber;
|
||||
}
|
||||
|
||||
public void setSerialNumber(String serialNumber) {
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
public String getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Certificate serial number '" + this.serialNumber + "' num of rows: " + this.rowCount + " start index: " + this.startIndex;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.core.config.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.util.List;
|
||||
|
||||
class DeviceInfoConfigurations {
|
||||
|
||||
private List<DeviceInfoItem> deviceInfoItems;
|
||||
|
||||
@XmlElement(name = "DeviceInfoItem")
|
||||
public List<DeviceInfoItem> getDeviceInfoItems() {
|
||||
return deviceInfoItems;
|
||||
}
|
||||
|
||||
public void setDeviceInfoItems(List<DeviceInfoItem> deviceInfoItems) {
|
||||
this.deviceInfoItems = deviceInfoItems;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.core.config.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
class DeviceInfoItem {
|
||||
|
||||
private String definedValue;
|
||||
private String displayValue;
|
||||
|
||||
private String type;
|
||||
|
||||
@XmlElement(name = "DefinedValue")
|
||||
public String getDefinedValue() {
|
||||
return definedValue;
|
||||
}
|
||||
|
||||
public void setDefinedValue(String definedValue) {
|
||||
this.definedValue = definedValue;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DisplayValue")
|
||||
public String getDisplayValue() {
|
||||
return displayValue;
|
||||
}
|
||||
|
||||
public void setDisplayValue(String displayValue) {
|
||||
this.displayValue = displayValue;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue