|
|
@ -50,13 +50,12 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService {
|
|
|
|
public class ApplicationManagerProviderServiceImpl implements ApplicationManagementProviderService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class);
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationMappingDAO applicationMappingDAO;
|
|
|
|
private ApplicationMappingDAO applicationMappingDAO;
|
|
|
|
|
|
|
|
|
|
|
|
private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(ApplicationManagerProviderServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig) {
|
|
|
|
public ApplicationManagerProviderServiceImpl(AppManagementConfig appManagementConfig) {
|
|
|
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
|
|
@ -198,17 +197,17 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|
|
|
public void updateApplicationListInstalledInDevice(
|
|
|
|
public void updateApplicationListInstalledInDevice(
|
|
|
|
DeviceIdentifier deviceIdentifier,
|
|
|
|
DeviceIdentifier deviceIdentifier,
|
|
|
|
List<Application> applications) throws ApplicationManagementException {
|
|
|
|
List<Application> applications) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Updating application list for device: " + deviceIdentifier.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
List<Application> installedAppList = getApplicationListForDevice(deviceIdentifier);
|
|
|
|
List<Application> installedAppList = getApplicationListForDevice(deviceIdentifier);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier,
|
|
|
|
Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier,
|
|
|
|
false);
|
|
|
|
false);
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Device:" + device.getId() + ":identifier:" + deviceIdentifier.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("num of apps installed:" + installedAppList.size());
|
|
|
|
log.debug("Number of apps installed:" + installedAppList.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Application> appsToAdd = new ArrayList<>();
|
|
|
|
List<Application> appsToAdd = new ArrayList<>();
|
|
|
|
List<Integer> appIdsToRemove = new ArrayList<>(installedAppList.size());
|
|
|
|
List<Integer> appIdsToRemove = new ArrayList<>(installedAppList.size());
|
|
|
@ -227,10 +226,11 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|
|
|
List<Integer> applicationIds = new ArrayList<>();
|
|
|
|
List<Integer> applicationIds = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
for (Application application : applications) {
|
|
|
|
for (Application application : applications) {
|
|
|
|
/*
|
|
|
|
// Adding N/A if application doesn't have a version. Also truncating the application version,
|
|
|
|
Truncating the application version if length of the version is greater than maximum allowed length.
|
|
|
|
// if length of the version is greater than maximum allowed length.
|
|
|
|
*/
|
|
|
|
if (application.getVersion() == null) {
|
|
|
|
if (application.getVersion().length() >
|
|
|
|
application.setVersion("N/A");
|
|
|
|
|
|
|
|
} else if (application.getVersion().length() >
|
|
|
|
DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH) {
|
|
|
|
DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH) {
|
|
|
|
application.setVersion(StringUtils.abbreviate(application.getVersion(),
|
|
|
|
application.setVersion(StringUtils.abbreviate(application.getVersion(),
|
|
|
|
DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH));
|
|
|
|
DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH));
|
|
|
@ -258,24 +258,34 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("num of remove app Ids:" + appIdsToRemove.size());
|
|
|
|
log.debug("num of remove app Ids:" + appIdsToRemove.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new ApplicationManagementException("Error occurred saving application list to the device", e);
|
|
|
|
String msg = "Error occurred saving application list of the device " + deviceIdentifier.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
throw new ApplicationManagementException("Error occurred while initializing transaction", e);
|
|
|
|
String msg = "Error occurred while initializing transaction for saving application list to the device "
|
|
|
|
|
|
|
|
+ deviceIdentifier.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
throw new ApplicationManagementException("Error occurred obtaining the device object.", e);
|
|
|
|
String msg = "Error occurred obtaining the device object for device " + deviceIdentifier.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
String msg = "Exception occurred saving application list of the device " + deviceIdentifier.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Application> getApplicationListForDevice(
|
|
|
|
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceId)
|
|
|
|
DeviceIdentifier deviceId) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
Device device = null;
|
|
|
|
Device device;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId,
|
|
|
|
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId,
|
|
|
|
false);
|
|
|
|
false);
|
|
|
@ -288,16 +298,24 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|
|
|
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
|
|
|
|
log.debug("No device is found upon the device identifier '" + deviceId.getId() +
|
|
|
|
"' and type '" + deviceId.getType() + "'. Therefore returning null");
|
|
|
|
"' and type '" + deviceId.getType() + "'. Therefore returning null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
return applicationDAO.getInstalledApplications(device.getId());
|
|
|
|
return applicationDAO.getInstalledApplications(device.getId());
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new ApplicationManagementException("Error occurred while fetching the Application List of '" +
|
|
|
|
String msg = "Error occurred while fetching the Application List of device " + deviceId.toString();
|
|
|
|
deviceId.getType() + "' device carrying the identifier'" + deviceId.getId(), e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ApplicationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
String msg = "Error occurred while opening a connection to the data source to get application " +
|
|
|
|
|
|
|
|
"list of the device " + deviceId.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
String msg = "Exception occurred getting application list of the device " + deviceId.toString();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|