Merge branch 'corrective-policy' into 'corrective-policy'

Fix activity details getting issue of a device

See merge request entgra/carbon-device-mgt!696
corrective-policy
Dharmakeerthi Lasantha 4 years ago
commit 56dec687c0

@ -339,13 +339,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream()); byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName()); applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
ApplicationInstaller applicationInstaller = null;
String packagename;
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) { if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
applicationInstaller = applicationStorageManager.getAppInstallerData(binary, deviceType); ApplicationInstaller applicationInstaller = applicationStorageManager
packagename = applicationInstaller.getPackageName(); .getAppInstallerData(binary, deviceType);
applicationReleaseDTO.setVersion(applicationInstaller.getVersion()); applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packagename); applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
} else { } else {
String windowsInstallerName = applicationArtifact.getInstallerName(); String windowsInstallerName = applicationArtifact.getInstallerName();
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1); String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
@ -356,16 +354,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
packagename = applicationReleaseDTO.getPackageName();
} }
String packageName = applicationReleaseDTO.getPackageName();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
if (!isNewRelease && applicationReleaseDAO if (!isNewRelease && applicationReleaseDAO
.isActiveReleaseExisitForPackageName(packagename, tenantId, .isActiveReleaseExisitForPackageName(packageName, tenantId,
lifecycleStateManager.getEndState())) { lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packagename String msg = "Application release is already exist for the package name: " + packageName
+ ". Either you can delete all application releases for package " + packagename + " or " + ". Either you can delete all application releases for package " + packageName + " or "
+ "you can add this app release as an new application release, under the existing " + "you can add this app release as an new application release, under the existing "
+ "application."; + "application.";
log.error(msg); log.error(msg);
@ -1925,13 +1923,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
int deviceTypeId; int deviceTypeId;
if (!deviceTypeName.equals(Constants.ALL)) { if (!deviceTypeName.equals(Constants.ALL)) {
DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName);
deviceTypeId = deviceType.getId();
if (deviceType == null) { if (deviceType == null) {
String msg = "Device type doesn't exist. Hence check the application name existence with valid " String msg = "Device type doesn't exist. Hence check the application name existence with valid "
+ "device type name."; + "device type name.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
deviceTypeId = deviceType.getId();
} else { } else {
//For web-clips device type = 'ALL' //For web-clips device type = 'ALL'
deviceTypeId = 0; deviceTypeId = 0;
@ -2678,6 +2676,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>( AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0)); applicationDTO.getApplicationReleaseDTOs().get(0));
validateAppReleaseUpdating(entAppReleaseWrapper, applicationDTO, applicationArtifact, validateAppReleaseUpdating(entAppReleaseWrapper, applicationDTO, applicationArtifact,
@ -2696,15 +2695,19 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) { if (!StringUtils.isEmpty(entAppReleaseWrapper.getMetaData())) {
applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData()); applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData());
} }
if (!StringUtils.isEmpty(entAppReleaseWrapper.getVersion())) { // Updating version
//If the application device type is WINDOWS, it is allowed to modify version number and package name.
if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceTypeObj.getName())) {
if (!StringUtils.isEmpty(entAppReleaseWrapper.getVersion())) {
applicationReleaseDTO.get().setVersion(entAppReleaseWrapper.getVersion()); applicationReleaseDTO.get().setVersion(entAppReleaseWrapper.getVersion());
} }
if (!StringUtils.isEmpty(entAppReleaseWrapper.getPackageName())) { // Updating packageName if (!StringUtils.isEmpty(entAppReleaseWrapper.getPackageName())) {
applicationReleaseDTO.get().setPackageName(entAppReleaseWrapper.getPackageName()); applicationReleaseDTO.get().setPackageName(entAppReleaseWrapper.getPackageName());
} }
}
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName()) if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())
&& applicationArtifact.getInstallerStream() != null) { && applicationArtifact.getInstallerStream() != null) {
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
applicationReleaseDTO applicationReleaseDTO
.set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(), .set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
applicationArtifact)); applicationArtifact));
@ -3135,17 +3138,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
unrestrictedRoles = applicationWrapper.getUnrestrictedRoles(); unrestrictedRoles = applicationWrapper.getUnrestrictedRoles();
//Validating the version number and the packageName of the Windows applications
if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(applicationWrapper.getDeviceType())) {
if (applicationWrapper.getEntAppReleaseWrappers().get(0).getVersion() == null ||
applicationWrapper.getEntAppReleaseWrappers().get(0).getPackageName() == null) {
String msg = "Application Version number or/and PackageName both are required only when the app type is " +
applicationWrapper.getDeviceType() + " platform type";
log.error(msg);
throw new BadRequestException(msg);
}
}
} else if (param instanceof WebAppWrapper) { } else if (param instanceof WebAppWrapper) {
WebAppWrapper webAppWrapper = (WebAppWrapper) param; WebAppWrapper webAppWrapper = (WebAppWrapper) param;
appName = webAppWrapper.getName(); appName = webAppWrapper.getName();
@ -3461,7 +3453,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId); List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId);
if (deviceSubIds.isEmpty() || deviceSubIds == null) { if (deviceSubIds.isEmpty()) {
return false; return false;
} }
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {

@ -650,22 +650,31 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Activity activity = null; Activity activity = null;
int responseId = 0;
List<ActivityStatus> activityStatusList = new ArrayList<>(); List<ActivityStatus> activityStatusList = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT eom.ENROLMENT_ID, eom.OPERATION_ID, eom.ID AS EOM_MAPPING_ID, dor.ID AS OP_RES_ID,\n" + String sql = "SELECT "
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" + + "eom.ENROLMENT_ID, "
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" + + "eom.OPERATION_ID, eom.ID AS EOM_MAPPING_ID, "
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" + + "dor.ID AS OP_RES_ID, "
"dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING AS eom \n" + + "de.DEVICE_ID, "
"INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID\n" + + "d.DEVICE_IDENTIFICATION, "
"INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID\n" + + "d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, "
"INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID \n" + + "eom.STATUS, eom.CREATED_TIMESTAMP, "
"INNER JOIN DM_DEVICE_TYPE AS dt ON dt.ID=d.DEVICE_TYPE_ID\n" + + "eom.UPDATED_TIMESTAMP, "
"LEFT JOIN DM_DEVICE_OPERATION_RESPONSE AS dor ON dor.ENROLMENT_ID=de.id \n" + + "op.OPERATION_CODE, "
"AND dor.OPERATION_ID = eom.OPERATION_ID\n" + + "op.TYPE AS OPERATION_TYPE, "
"WHERE eom.OPERATION_ID = ? AND de.device_id = ? AND de.TENANT_ID = ?"; + "dor.OPERATION_RESPONSE, "
+ "dor.RECEIVED_TIMESTAMP, "
+ "dor.IS_LARGE_RESPONSE, "
+ "op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING AS eom "
+ "INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID "
+ "INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID "
+ "INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID "
+ "INNER JOIN DM_DEVICE_TYPE AS dt ON dt.ID=d.DEVICE_TYPE_ID "
+ "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE AS dor ON dor.ENROLMENT_ID=de.id "
+ "AND dor.OPERATION_ID = eom.OPERATION_ID "
+ "WHERE eom.OPERATION_ID = ? AND de.device_id = ? AND de.TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
@ -682,37 +691,40 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity = new Activity(); activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCreatedTimeStamp(
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE")); activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY")); activity.setInitiatedBy(rs.getString("INITIATED_BY"));
} }
if (enrolmentId != rs.getInt("ENROLMENT_ID")) { if (enrolmentId != rs.getInt("ENROLMENT_ID")) {
activityStatus = new ActivityStatus(); activityStatus = new ActivityStatus();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"),
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); rs.getString("DEVICE_TYPE_NAME"));
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
deviceIdentifier.setType(rs.getString("DEVICE_TYPE_NAME"));
activityStatus.setDeviceIdentifier(deviceIdentifier); activityStatus.setDeviceIdentifier(deviceIdentifier);
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS"))); activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); activityStatus.setUpdatedTimestamp(
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
largeResponseIDs.add(rs.getInt("OP_RES_ID"));
} else {
operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
} }
}
activityStatus.setResponses(operationResponses); activityStatus.setResponses(operationResponses);
activityStatusList.add(activityStatus); activityStatusList.add(activityStatus);
enrolmentId = rs.getInt("ENROLMENT_ID"); enrolmentId = rs.getInt("ENROLMENT_ID");
activity.setActivityStatus(activityStatusList); activity.setActivityStatus(activityStatusList);
} else { } else {
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
responseId = rs.getInt("OP_RES_ID");
if (rs.getBoolean("IS_LARGE_RESPONSE")) { if (rs.getBoolean("IS_LARGE_RESPONSE")) {
largeResponseIDs.add(responseId); largeResponseIDs.add(rs.getInt("OP_RES_ID"));
} else { } else {
if (activityStatus == null) {
activityStatus = new ActivityStatus();
}
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs)); activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
} }
} }

Loading…
Cancel
Save