|
|
|
@ -86,7 +86,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
private LifecycleStateDAO lifecycleStateDAO;
|
|
|
|
|
private LifecycleStateManger lifecycleStateManger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ApplicationManagerImpl() {
|
|
|
|
|
initDataAccessObjects();
|
|
|
|
|
lifecycleStateManger = DataHolder.getInstance().getLifecycleStateManager();
|
|
|
|
@ -106,8 +105,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
* @throws RequestValidatingException if application creating request is invalid, returns {@link RequestValidatingException}
|
|
|
|
|
* @throws ApplicationManagementException Catch all other throwing exceptions and returns {@link ApplicationManagementException}
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Application createApplication(Application application)
|
|
|
|
|
@Override public Application createApplication(Application application)
|
|
|
|
|
throws RequestValidatingException, ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -205,11 +203,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
|
|
|
|
|
@Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
ApplicationList applicationList;
|
|
|
|
|
List<Application> appList;
|
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
|
|
|
|
|
|
filter = validateFilter(filter);
|
|
|
|
@ -218,9 +216,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (filter.getDeviceType() != null ) {
|
|
|
|
|
boolean isValidDeviceType = false;
|
|
|
|
|
String deviceType = filter.getDeviceType().getName();
|
|
|
|
|
List<DeviceType> deviceTypes = Util.getDeviceManagementService().getDeviceTypes();
|
|
|
|
|
for (DeviceType dt : deviceTypes) {
|
|
|
|
|
if (dt.getName().equals(deviceType)) {
|
|
|
|
|
filter.getDeviceType().setId(dt.getId());
|
|
|
|
|
isValidDeviceType = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isValidDeviceType) {
|
|
|
|
|
throw new BadRequestException("Invalid device type is found, device type is " + deviceType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
|
if(applicationList != null && applicationList.getApplications() != null && !applicationList
|
|
|
|
|
appList = applicationList.getApplications();
|
|
|
|
|
for ( Application app : appList){
|
|
|
|
|
if (AppLifecycleState.REMOVED.toString().equals(app.getStatus())){
|
|
|
|
|
appList.remove(app);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
applicationList.setApplications(appList);
|
|
|
|
|
if (applicationList.getApplications() != null && !applicationList
|
|
|
|
|
.getApplications().isEmpty()) {
|
|
|
|
|
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
|
applicationList = getRoleRestrictedApplicationList(applicationList, userName);
|
|
|
|
@ -238,13 +258,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
"DAO exception while getting applications for the user " + userName + " of tenant " + tenantId, e);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
"Error Occured when getting device type instance for " + filter.getDeviceType());
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease)
|
|
|
|
|
@Override public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -256,8 +278,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
Application existingApplication = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
|
if (existingApplication == null) {
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
"Couldn't find application for the application Id: " + applicationId);
|
|
|
|
|
throw new NotFoundException("Couldn't find application for the application Id: " + applicationId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo check whether admin or app creator.
|
|
|
|
@ -286,7 +307,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
.createRelease(applicationRelease, existingApplication.getId(), tenantId);
|
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstant(AppLifecycleState.CREATED.toString(),
|
|
|
|
|
AppLifecycleState.CREATED.toString());
|
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), tenantId);
|
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
|
.addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(), tenantId);
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return applicationRelease;
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
@ -317,8 +339,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
|
@Override public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
Application application;
|
|
|
|
@ -358,8 +379,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
|
|
|
|
|
@Override public Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
Application application;
|
|
|
|
@ -399,8 +419,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isRoleExists(Collection<String> unrestrictedRoleList, String userName)
|
|
|
|
|
throws UserStoreException {
|
|
|
|
|
private boolean isRoleExists(Collection<String> unrestrictedRoleList, String userName) throws UserStoreException {
|
|
|
|
|
String[] roleList;
|
|
|
|
|
roleList = getRolesOfUser(userName);
|
|
|
|
|
for (String unrestrictedRole : unrestrictedRoleList) {
|
|
|
|
@ -462,8 +481,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Application getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException {
|
|
|
|
|
@Override public Application getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
Application application;
|
|
|
|
@ -521,8 +539,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AppLifecycleState.PUBLISHED.toString()
|
|
|
|
|
.equals(state) && filteredReleases.size() > 1) {
|
|
|
|
|
if (AppLifecycleState.PUBLISHED.toString().equals(state) && filteredReleases.size() > 1) {
|
|
|
|
|
log.warn("There are more than one application releases is found which is in PUBLISHED state");
|
|
|
|
|
filteredReleases.sort((r1, r2) -> {
|
|
|
|
|
if (r1.getLifecycleState().getUpdatedAt().after(r2.getLifecycleState().getUpdatedAt())) {
|
|
|
|
@ -538,8 +555,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
return applicationReleases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> deleteApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
|
@Override public List<String> deleteApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
List<String> storedLocations = new ArrayList<>();
|
|
|
|
@ -549,7 +565,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
application = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (application == null) {
|
|
|
|
|
throw new NotFoundException("Couldn't found an application for Application ID: " + applicationId);
|
|
|
|
|
}
|
|
|
|
@ -589,7 +604,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
"Can't delete application release which has the UUID:" + applicationRelease
|
|
|
|
|
.getUuid() + " and its belongs to the application which has application ID:"
|
|
|
|
|
.getUuid()
|
|
|
|
|
+ " and its belongs to the application which has application ID:"
|
|
|
|
|
+ applicationId + " You have to move the lifecycle state from "
|
|
|
|
|
+ currentState + " to acceptable state");
|
|
|
|
|
}
|
|
|
|
@ -663,8 +679,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
return directions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String deleteApplicationRelease(int applicationId, String releaseUuid)
|
|
|
|
|
@Override public String deleteApplicationRelease(int applicationId, String releaseUuid)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -911,8 +926,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//todo check whether package names are same
|
|
|
|
|
@Override
|
|
|
|
|
public void updateApplicationArtifact(int appId, String deviceType, String uuid, InputStream binaryFile)
|
|
|
|
|
@Override public void updateApplicationArtifact(int appId, String deviceType, String uuid, InputStream binaryFile)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
@ -928,8 +942,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
if (!isValidDeviceType) {
|
|
|
|
|
throw new ValidationException(
|
|
|
|
|
"Invalid request to update application release artifact, invalid application type: " + deviceType
|
|
|
|
|
+ " for Application id: " + appId + " application release uuid: " + uuid);
|
|
|
|
|
"Invalid request to update application release artifact, invalid application type: "
|
|
|
|
|
+ deviceType + " for Application id: " + appId + " application release uuid: " + uuid);
|
|
|
|
|
}
|
|
|
|
|
if (appId <= 0) {
|
|
|
|
|
throw new ValidationException(
|
|
|
|
@ -1029,9 +1043,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws
|
|
|
|
|
ApplicationManagementException {
|
|
|
|
|
@Override public LifecycleState getLifecycleState(int applicationId, String releaseUuid)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
LifecycleState lifecycleState;
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
@ -1039,7 +1052,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
if (lifecycleState == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger.getNextLifecycleStates(lifecycleState.getCurrentState())));
|
|
|
|
|
lifecycleState.setNextStates(
|
|
|
|
|
new ArrayList<>(lifecycleStateManger.getNextLifecycleStates(lifecycleState.getCurrentState())));
|
|
|
|
|
|
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
|
throw new ApplicationManagementException("Failed to get lifecycle state from database", e);
|
|
|
|
@ -1049,8 +1063,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
return lifecycleState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state)
|
|
|
|
|
@Override public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
try {
|
|
|
|
@ -1098,8 +1111,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Application updateApplication(int applicationId, Application application) throws ApplicationManagementException{
|
|
|
|
|
@Override public Application updateApplication(int applicationId, Application application)
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
@ -1115,8 +1128,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
existingApplication = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
|
if (existingApplication == null) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new NotFoundException("Tried to update Application which is not in the publisher, " +
|
|
|
|
|
"Please verify application details");
|
|
|
|
|
throw new NotFoundException("Tried to update Application which is not in the publisher, "
|
|
|
|
|
+ "Please verify application details");
|
|
|
|
|
}
|
|
|
|
|
if (!existingApplication.getUnrestrictedRoles().isEmpty()) {
|
|
|
|
|
isExistingAppRestricted = true;
|
|
|
|
@ -1183,8 +1196,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
"Error occurred while updating the application, application id: " + applicationId);
|
|
|
|
|
}
|
|
|
|
|
catch (VisibilityManagementDAOException e){
|
|
|
|
|
} catch (VisibilityManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
"Error occurred while updating the visibility restriction of the application. Application id is "
|
|
|
|
@ -1244,10 +1256,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//todo check whether package names are same
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateRelease(int applicationId, String releaseUuid, String deviceType, ApplicationRelease updateRelease,
|
|
|
|
|
InputStream binaryFileStram, InputStream iconFileStream, InputStream bannerFileStream,
|
|
|
|
|
List<InputStream> attachments) throws ApplicationManagementException{
|
|
|
|
|
@Override public boolean updateRelease(int applicationId, String releaseUuid, String deviceType,
|
|
|
|
|
ApplicationRelease updateRelease, InputStream binaryFileStram, InputStream iconFileStream,
|
|
|
|
|
InputStream bannerFileStream, List<InputStream> attachments) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|