/** * Reinitaliser les position de publication dans la section * * @param p * @param s * @throws MappingException */ public static void removePublication(Publication p, Section s) throws MappingException { SectionPublication impl = ((PublicationImpl) p).findSectionPublication(s); try { if (impl != null) { // mettre à jour les autres en diminuant int currentIndex = impl.getIndex(); OQLQuery oql = Mapping.getInstance() .getDb() .getOQLQuery( "SELECT sp FROM org.nextime.ion.framework.business.impl.SectionPublicationImpl sp " + " WHERE sp.section = $1 AND sp.index > $2 "); oql.bind(s.getId()); oql.bind(currentIndex); QueryResults results = oql.execute(); while (results.hasMore()) { SectionPublication sp = (SectionPublication) results.next(); sp.setIndex(sp.getIndex() - 1); } } } catch (PersistenceException e) { Logger.getInstance() .error( "Error de mettre à jour les sections_publications la publicaiton ", PublicationSorter.class, e); throw new MappingException( "Error de mettre à jour les sections_publications la publicaiton "); } return; /* try { Vector publications = s.listPublications(); int index = Integer.parseInt(p.getMetaData("index_" + s.getId()) + ""); for (int i = 0; i < publications.size(); i++) { Publication tp = (Publication) publications.get(i); int tindex = Integer.parseInt(tp.getMetaData("index_" + s.getId()) + ""); if (tindex > index) { tp.setMetaData("index_" + s.getId(), (tindex - 1) + ""); } } } catch (Exception e) { //e.printStackTrace(); org.nextime.ion.framework.logger.Logger.getInstance().error( e.getMessage(), PublicationSorter.class); }*/ }
public static void downPublication(Publication p, Section s) throws MappingException { SectionPublication currentSP = SectionPublication.findSectionPublication(s, p); int currentIndex = currentSP.getIndex(); SectionPublication previousSP = SectionPublication.findPreviousSectionPublication(s, currentIndex); if (previousSP != null) { int previousIndex = previousSP.getIndex(); currentSP.setIndex(previousIndex); previousSP.setIndex(currentIndex); } /* try { int currentIndex = Integer.parseInt(p.getMetaData("index_" + s.getId()) + ""); int newIndex = currentIndex - 1; Vector publications = s.listPublications(); if (newIndex < 1) { newIndex = 1; } else { for (int i = 0; i < publications.size(); i++) { if (newIndex == Integer .parseInt(((Publication) publications.get(i)) .getMetaData("index_" + s.getId()) + "")) { Publication pac = (Publication) publications.get(i); pac.setMetaData("index_" + s.getId(), (Integer .parseInt(pac.getMetaData("index_" + s.getId()) + "") + 1) + ""); } } } p.setMetaData("index_" + s.getId(), newIndex + ""); } catch (Exception e) { //e.printStackTrace(); org.nextime.ion.framework.logger.Logger.getInstance().error( e.getMessage(), PublicationSorter.class,e); } */ }