adding app manager changes - not complete

feature/appm-store/pbac
lasantha 7 years ago
parent 460bda420b
commit 1c6393959d

@ -290,7 +290,7 @@ public interface ApplicationManagementAPI {
@Valid Application application); @Valid Application application);
@POST @POST
@Path("/release") @Path("{appId}/release")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(
@ -319,13 +319,10 @@ public interface ApplicationManagementAPI {
}) })
Response createApplicationRelease( Response createApplicationRelease(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease, @Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease,
@Multipart(value = "binaryFile") Attachment binaryFile); @Multipart(value = "binaryFile") Attachment binaryFile,
@PathParam("appId") int applicationId));
@POST @POST
@Path("/upload-artifacts/{uuid}") @Path("/upload-artifacts/{uuid}")

@ -199,16 +199,15 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
//working on this//
@POST @POST
@Consumes("application/json") @Consumes("application/json")
public Response createApplication(@Valid Application application) { public Response createApplication(@Valid Application application) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Application application2 = applicationManager.createApplication(application); Application createdApplication = applicationManager.createApplication(application);
if (application != null){ if (application != null){
return Response.status(Response.Status.CREATED).entity(application2).build(); return Response.status(Response.Status.CREATED).entity(createdApplication).build();
}else{ }else{
String msg = "Given device type is not matched with existing device types"; String msg = "Given device type is not matched with existing device types";
log.error(msg); log.error(msg);
@ -225,9 +224,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
//working on this//
@Override @Override
@POST @POST
@Path("/release") @Path("{appId}/release")
public Response createApplicationRelease(@Multipart("applicationRelease") ApplicationRelease applicationRelease, public Response createApplicationRelease(@Multipart("applicationRelease") ApplicationRelease applicationRelease,
@Multipart("binaryFile") Attachment binaryFile) { @Multipart("binaryFile") Attachment binaryFile) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();

@ -39,7 +39,7 @@ public interface ApplicationManager {
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
Application createApplication(Application application) Application createApplication(Application application)
throws ApplicationManagementException, DeviceManagementDAOException, DeviceManagementDAOException; throws ApplicationManagementException, DeviceManagementDAOException;
/** /**
* Updates an already existing application. * Updates an already existing application.

@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
@ -46,7 +47,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private LifecycleDAO lifecycleDAO; private VisibilityDAO visibilityDAO;
private LifecycleStateDAO lifecycleStateDAO; private LifecycleStateDAO lifecycleStateDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
@ -57,7 +58,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private void initDataAccessObjects() { private void initDataAccessObjects() {
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
this.lifecycleDAO = ApplicationManagementDAOFactory.getLifecycleDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
@ -67,8 +68,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
public Application createApplication(Application application) public Application createApplication(Application application)
throws ApplicationManagementException, DeviceManagementDAOException { throws ApplicationManagementException, DeviceManagementDAOException {
application.setUser(new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(), User loggedInUser = new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true))); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
application.setUser(loggedInUser);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Create Application received for the tenant : " + application.getUser().getTenantId() + " From" log.debug("Create Application received for the tenant : " + application.getUser().getTenantId() + " From"
+ " the user : " + application.getUser().getUserName()); + " the user : " + application.getUser().getUserName());
@ -96,7 +98,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.applicationDAO.addTags(application.getTags(), appId, tenantId); this.applicationDAO.addTags(application.getTags(), appId, tenantId);
} }
if (application.getIsRestricted() == 1 && !application.getUnrestrictedRoles().isEmpty()){ if (application.getIsRestricted() == 1 && !application.getUnrestrictedRoles().isEmpty()){
this.applicationDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId); this.visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId);
}else{ }else{
application.setIsRestricted(0); application.setIsRestricted(0);
} }
@ -118,48 +120,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
}finally { }finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
// validateApplication(application);
// application.setUuid(HelperUtil.generateApplicationUuid());
//// application.setCreatedAt(new Date());
//// application.setModifiedAt(new Date());
//
//// Category category = DataHolder.getInstance().getCategoryManager()
//// .getCategory(application.getCategory().getName());
//// if (category == null) {
//// throw new NotFoundException("Invalid Category is provided for the application " + application.getUuid());
//// }
//// application.setCategory(category);
// try {
// ConnectionManagerUtil.beginDBTransaction();
//// if (log.isDebugEnabled()) {
//// log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
//// + platform.getIdentifier() + " is found");
//// }
// LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
// LifecycleState lifecycleState = lifecycleStateDAO.getLifeCycleStateByIdentifier(CREATED);
//
// if (lifecycleState == null) {
// ConnectionManagerUtil.commitDBTransaction();
// throw new NotFoundException("Invalid lifecycle state.");
// }
//
// Lifecycle lifecycle = new Lifecycle();
// lifecycle.setCreatedAt(new Date());
// lifecycle.setCreatedBy(application.getUser().getUserName());
//
//
//// application.setCurrentLifecycle(lifecycle);
// application = ApplicationManagementDAOFactory.getApplicationDAO().createApplication(application);
//// DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility());
// ConnectionManagerUtil.commitDBTransaction();
// return application;
// } catch (ApplicationManagementException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw e;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
} }
@Override @Override
@ -254,30 +214,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
//
// try { try {
// if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAuthorized(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
// userName = "ALL"; userName = "ALL";
// } }
// } catch (UserStoreException e) { } catch (UserStoreException e) {
// throw new ApplicationManagementException("User-store exception while checking whether the user " + throw new ApplicationManagementException("User-store exception while checking whether the user " +
// userName + " of tenant " + tenantId + " has the publisher permission"); userName + " of tenant " + tenantId + " has the publisher permission");
// } }
// filter.setUserName(userName); filter.setUserName(userName);
//
// try { try {
// ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
// ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
// for (Application application : applicationList.getApplications()) { for (Application application : applicationList.getApplications()) {
// application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
// } }
// return applicationList; return applicationList;
// } finally { } finally {
// ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
// } }
} }
@Override @Override

Loading…
Cancel
Save