private PackageAction syncToVictim( RequestContext requestContext, Long sid, Set pkgIdCombos, String option) { PackageAction pa = null; Date time = new Date(requestContext.getParamAsLong("time")); if (isProfileSync(requestContext)) { Long prid = requestContext.getRequiredParam("prid"); pa = ProfileManager.syncToProfile( requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time); if (pa == null) { createMessage(requestContext.getRequest(), "message.nopackagestosync"); return null; } List args = new ArrayList(); args.add(sid.toString()); args.add(pa.getId().toString()); args.add(requestContext.lookupAndBindServer().getName()); args.add( ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg()) .getName()); createMessage(requestContext.getRequest(), "message.syncpackages", args); } else if (isSystemSync(requestContext)) { Long sid1 = requestContext.getRequiredParam("sid_1"); pa = ProfileManager.syncToSystem( requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time); if (pa == null) { createMessage(requestContext.getRequest(), "message.nopackagestosync"); return null; } List args = new ArrayList(); args.add(sid.toString()); args.add(pa.getId().toString()); args.add(requestContext.lookupAndBindServer().getName()); args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName()); createMessage(requestContext.getRequest(), "message.syncpackages", args); } addHardwareMessage(pa, requestContext); return pa; }
public void testCreatePackageUpdateActionWithName() throws Exception { User usr = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName()); PackageAction testAction = (PackageAction) ActionFactoryTest.createAction(usr, ActionFactory.TYPE_PACKAGES_UPDATE); PackageActionDetailsTest.createTestDetailsWithName(usr, testAction); ActionFactory.save(testAction); flushAndEvict(testAction); /** Get action back out of db and make sure it committed correctly */ Action same = ActionFactory.lookupById(testAction.getId()); assertTrue(same instanceof PackageAction); PackageAction sameAction = (PackageAction) same; assertNotNull(sameAction.getDetails()); assertEquals(sameAction.getDetails().size(), 2); assertNotNull(sameAction.getDetails().toArray()[0]); assertNotNull(sameAction.getDetails().toArray()[1]); assertEquals(sameAction.getName(), testAction.getName()); assertEquals(sameAction.getId(), testAction.getId()); }
/** * Test fetching a PackageAction * * @throws Exception */ public void testLookupPackageAction() throws Exception { Action newA = ActionFactoryTest.createAction( UserTestUtils.createUser( "testUser", UserTestUtils.createOrg("testOrg" + this.getClass().getSimpleName())), ActionFactory.TYPE_PACKAGES_VERIFY); assertNotNull(newA.getId()); assertTrue(newA instanceof PackageAction); PackageAction p = (PackageAction) newA; assertNotNull(p.getDetails()); assertEquals(p.getDetails().size(), 1); PackageActionDetails firstDetail = (PackageActionDetails) p.getDetails().toArray()[0]; /** Make sure PackageEvr was set & committed correctly */ Set details = p.getDetails(); Iterator ditr = details.iterator(); while (ditr.hasNext()) { PackageActionDetails detail = (PackageActionDetails) ditr.next(); assertNotNull(detail.getEvr().getId()); } User user = UserTestUtils.findNewUser("TEST USER", "TEST ORG"); Server testserver = ServerFactoryTest.createTestServer(user); PackageActionResult result = new PackageActionResult(); result.setServer(testserver); result.setDetails(firstDetail); result.setResultCode(new Long(42)); result.setCreated(new Date()); result.setModified(new Date()); firstDetail.addResult(result); ActionFactory.save(p); PackageAction p2 = (PackageAction) ActionFactory.lookupById(p.getId()); assertNotNull(p2.getDetails()); assertEquals(p2.getDetails().size(), 1); assertNotNull(p2.getDetails().toArray()[0]); firstDetail = (PackageActionDetails) p2.getDetails().toArray()[0]; assertNotNull(firstDetail.getResults()); assertEquals(firstDetail.getResults().size(), 1); }
public void testCreatePackageRemoveAction() throws Exception { User user = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName()); Server srvr = ServerFactoryTest.createTestServer(user); ServerAction sa = new ServerAction(); sa.setStatus(ActionFactory.STATUS_QUEUED); sa.setRemainingTries(new Long(10)); sa.setServer(srvr); log.debug("Creating PackageRemoveAction."); PackageAction pra = (PackageAction) ActionFactory.createAction(ActionFactory.TYPE_PACKAGES_REMOVE); pra.setOrg(user.getOrg()); pra.setName("Package Removal"); pra.addServerAction(sa); sa.setParentAction(pra); log.debug("Committing PackageRemoveAction."); ActionFactory.save(pra); PackageAction result = (PackageAction) ActionFactory.lookupById(pra.getId()); assertEquals(pra, result); }
/** * Executes the appropriate PackageAction * * @param mapping ActionMapping * @param formIn ActionForm * @param request ServletRequest * @param response ServletResponse * @return The ActionForward to go to next. */ public ActionForward executePackageAction( ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext requestContext = new RequestContext(request); StrutsDelegate strutsDelegate = getStrutsDelegate(); Long sid = requestContext.getRequiredParam("sid"); User user = requestContext.getCurrentUser(); // updateList(newactions, user.getId()); List<Map<String, Long>> data = PackageListItem.toKeyMaps(getDataResult(request)); int numPackages = data.size(); // Archive the actions Server server = SystemManager.lookupByIdAndUser(sid, user); // The earliest time to perform the action. DynaActionForm dynaActionForm = (DynaActionForm) formIn; Date earliest = getStrutsDelegate().readDatePicker(dynaActionForm, "date", DatePicker.YEAR_RANGE_POSITIVE); // The action chain to append this action to, if any ActionChain actionChain = ActionChainHelper.readActionChain(dynaActionForm, user); PackageAction pa = schedulePackageAction(formIn, requestContext, data, earliest, actionChain); // Remove the actions from the users set SessionSetHelper.obliterate(request, getDecl(sid)); ActionMessages msgs = new ActionMessages(); if (actionChain == null) { /** * If there was only one action archived, display the "action" archived message, else display * the "actions" archived message. */ if (numPackages == 1) { msgs.add( ActionMessages.GLOBAL_MESSAGE, new ActionMessage( getMessageKeyForOne(), LocalizationService.getInstance().formatNumber(numPackages), pa.getId().toString(), sid.toString(), StringUtil.htmlifyText(server.getName()))); } else { msgs.add( ActionMessages.GLOBAL_MESSAGE, new ActionMessage( getMessageKeyForMany(), LocalizationService.getInstance().formatNumber(numPackages), pa.getId().toString(), sid.toString(), StringUtil.htmlifyText(server.getName()))); } } else { msgs.add( ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "message.addedtoactionchain", actionChain.getId(), StringUtil.htmlifyText(actionChain.getLabel()))); } strutsDelegate.saveMessages(request, msgs); Map params = new HashMap(); processParamMap(formIn, request, params); return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params); }