public String deleteSub() { // delete a planet subscription log.debug("Deleting Planet Subscription ..."); PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager(); try { if (!StringUtils.isEmpty(getSubid())) { Subscription sub = pmgr.getSubscriptionById(getSubid()); if (sub == null) { setError("PlanetGroupForm.error.nullSubscription"); return INPUT; } else { PlanetGroup group = getGroup(); group.getSubscriptions().remove(sub); sub.getGroups().remove(group); pmgr.saveGroup(group); PlanetFactory.getPlanet().flush(); } setSuccess("PlanetGroupForm.message.subscriptionDeleteSucceeded", sub.getTitle()); } else { setError("PlanetGroupForm.error.subscriptionNull"); } return INPUT; } catch (PlanetException ex) { log.error("Unable to lookup planet group", ex); setError("PlanetGroupForm.error.subscriptionDeleteFailed", getSubid()); return INPUT; } }
// Validation - sub url cannot be null, must be valid url public String addSub() { // add a planet subscription log.debug("Adding Planet Subscription ..."); PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager(); try { PlanetGroup group = getGroup(); if (group == null) { setError("PlanetSubscriptionForm.error.groupNull"); return INPUT; } // check if this subscription already exists before adding it Subscription sub = pMgr.getSubscription(getAddSubUrl()); if (sub == null) { // sub doesn't exist yet, so we need to fetch it FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher(); sub = fetcher.fetchSubscription(getAddSubUrl()); // save new sub pMgr.saveSubscription(sub); } // add the sub to the group group.getSubscriptions().add(sub); sub.getGroups().add(group); pMgr.saveGroup(group); // flush changes PlanetFactory.getPlanet().flush(); // clear field after success setAddSubUrl(null); } catch (PlanetException ex) { log.error("Error adding subscription", ex); setError("PlanetSubscriptionForm.error.saveFailed"); return INPUT; } setSuccess("PlanetSubscriptionForm.message.saveSucceeded"); return INPUT; }
// TODO: Validation - check that group handle is unique within planet // TODO: Validation - make sure that html is not allowed in handle or title // TODO: Validation - make sure maxXXXEntries have a proper value range public String save() { // save a group group log.debug("Saving Planet Group ..."); try { PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager(); pMgr.saveGroup(this.group); PlanetFactory.getPlanet().flush(); // call setGroupid() just in case this was a new group with no id yet setGroupid(this.group.getId()); } catch (PlanetException ex) { log.error("Error saving planet group", ex); setError("PlanetGroupForm.error.saveFailed"); return INPUT; } setSuccess("PlanetGroupForm.message.saveSucceeded"); return INPUT; }