@Override public boolean equals(Object o) { if (o instanceof PublicationDetail) { PublicationDetail anotherPublication = (PublicationDetail) o; return this.pk.equals(anotherPublication.getPK()); } return false; }
/** * add a new content. It is registered to contentManager service * * @param con a Connection * @param pubDetail the content to register * @param userId the creator of the content * @return the unique silverObjectId which identified the new content */ public int createSilverContent(Connection con, PublicationDetail pubDetail, String userId) throws ContentManagerException { // SilverTrace.info("blog","BlogContentManager.createSilverContent()", // "root.MSG_GEN_ENTER_METHOD", // "SilverContentVisibility = "+scv.toString()); return getContentManager() .addSilverContent( con, pubDetail.getPK().getId(), pubDetail.getPK().getComponentName(), userId); }
private void updateSilverContentVisibility( SilverContentVisibility scv, PublicationDetail pubDetail, int silverContentId) throws ContentManagerException { if (silverContentId == -1) { createSilverContent(null, pubDetail, pubDetail.getUpdaterId()); } else { getContentManager() .updateSilverContentVisibilityAttributes( scv, pubDetail.getPK().getComponentName(), silverContentId); } ClassifyEngine.clearCache(); }
/** * return a list of silverContent according to a list of publicationPK * * @param ids a list of publicationPK * @return a list of publicationDetail */ private List<PublicationDetail> getHeaders(List<PublicationPK> ids) { ArrayList<PublicationDetail> headers = new ArrayList<PublicationDetail>(); try { Collection<PublicationDetail> publicationDetails = getPublicationBm().getPublications(ids); for (PublicationDetail pubDetail : publicationDetails) { pubDetail.setIconUrl("blogSmall.gif"); headers.add(pubDetail); } } catch (RemoteException e) { // skip unknown and ill formed id. } return headers; }
/** * add a new content. It is registered to contentManager service * * @param con a Connection * @param pubDetail the content to register * @param userId the creator of the content * @return the unique silverObjectId which identified the new content */ public int createSilverContent(Connection con, PublicationDetail pubDetail, String userId) throws ContentManagerException { SilverContentVisibility scv = new SilverContentVisibility( pubDetail.getBeginDate(), pubDetail.getEndDate(), isVisible(pubDetail)); SilverTrace.info( "kmelia", "KmeliaContentManager.createSilverContent()", "root.MSG_GEN_ENTER_METHOD", "SilverContentVisibility = " + scv.toString()); return getContentManager() .addSilverContent( con, pubDetail.getPK().getId(), pubDetail.getPK().getComponentName(), userId, scv); }
/** * update the visibility attributes of the content. Here, the type of content is a * PublicationDetail * * @param pubDetail the content * @param silverObjectId the unique identifier of the content */ public void updateSilverContentVisibility(PublicationDetail pubDetail, boolean isVisible) throws ContentManagerException { int silverContentId = getContentManager() .getSilverContentId(pubDetail.getPK().getId(), pubDetail.getPK().getComponentName()); SilverContentVisibility scv = new SilverContentVisibility(pubDetail.getBeginDate(), pubDetail.getEndDate(), isVisible); SilverTrace.info( "kmelia", "KmeliaContentManager.updateSilverContentVisibility()", "root.MSG_GEN_ENTER_METHOD", "SilverContentVisibility = " + scv.toString()); updateSilverContentVisibility(scv, pubDetail, silverContentId); }
/** * Method declaration * * @param spaceId * @param componentId * @return * @see */ public Collection getVolume(String spaceId, String componentId) throws Exception { ArrayList myArrayList = new ArrayList(); Collection c = getPublications(spaceId, componentId); Iterator iter = c.iterator(); while (iter.hasNext()) { PublicationDetail detail = (PublicationDetail) iter.next(); UserIdCountVolumeCouple myCouple = new UserIdCountVolumeCouple(); myCouple.setUserId(detail.getCreatorId()); myCouple.setCountVolume(1); myArrayList.add(myCouple); } return myArrayList; }
/** * return a list of silverContent according to a list of publicationPK * * @param ids a list of publicationPK * @return a list of publicationDetail */ private List<PublicationDetail> getHeaders( List<PublicationPK> ids, String componentId, String userId) { List<PublicationDetail> headers = new ArrayList<PublicationDetail>(); try { KmeliaSecurity security = new KmeliaSecurity(); boolean checkRights = security.isRightsOnTopicsEnabled(componentId); Collection<PublicationDetail> publicationDetails = getPublicationBm().getPublications(ids); for (PublicationDetail pubDetail : publicationDetails) { if (!checkRights || security.isPublicationAvailable(pubDetail.getPK(), userId)) { pubDetail.setIconUrl("kmeliaSmall.gif"); headers.add(pubDetail); } } } catch (RemoteException e) { // skip unknown and ill formed id. } return headers; }
private List<PublicationDetail> filterPublications( List<PublicationDetail> publications, int nbPublis) { List<PublicationDetail> filteredPublications = new ArrayList<PublicationDetail>(); KmeliaSecurity security = new KmeliaSecurity(); PublicationDetail pub = null; for (int p = 0; publications != null && p < publications.size(); p++) { pub = publications.get(p); if (security.isObjectAvailable( pub.getPK().getInstanceId(), userId, pub.getPK().getId(), "Publication")) { filteredPublications.add(pub); } if (nbPublis != -1 && filteredPublications.size() == nbPublis) { return filteredPublications; } } return filteredPublications; }
/** * Selection des éléments nécessaires à la construction de l'url de l'item. * * @return * @throws Exception */ public String getUrl() throws Exception { PublicationDetail pub = null; NodeDetail node = null; String page = ""; if (idTopic != null) { node = themetracker.getTopic(idTopic); } else if (idPub != null) { pub = themetracker.getPublicationDetail(idPub); Collection<NodePK> fathers = pub.getPublicationBm().getAllFatherPK(pub.getPK()); Iterator<NodePK> it = fathers.iterator(); while (it.hasNext()) { NodePK pk = it.next(); node = themetracker.getTopic(pk.getId()); if (excludeTopicNamed != null) { StringTokenizer st = new StringTokenizer(node.getFullPath(), "/"); boolean found = false; while (st.hasMoreTokens()) { if (themetracker.getTopic(st.nextToken()).getName().equals(excludeTopicNamed)) { found = true; break; } } if (found == false) break; } else { break; } } @SuppressWarnings("unchecked") Collection<PublicationDetail> pubs = themetracker.getPublicationsByTopic(node.getId() + ",order,asc"); Iterator<PublicationDetail> iPubs = pubs.iterator(); int order = 1; while (iPubs.hasNext()) { PublicationDetail p = iPubs.next(); if (p.getId().equals(pub.getId())) break; order++; } if (order > 1) page = "-" + order; } else { throw new Exception("Pas de publication ou de theme"); } if (Boolean.parseBoolean(usePageNumber)) { return generateFullSemanticPath(node, pub) + page; } else { return generateFullSemanticPath(node, pub) + "-" + idPub; } }
@Override public Object clone() { PublicationDetail clone = new PublicationDetail(); clone.setAuthor(author); clone.setBeginDate(beginDate); clone.setBeginHour(beginHour); clone.setContent(content); clone.setCreationDate(creationDate); clone.setCreatorId(creatorId); clone.setDescription(getDescription()); clone.setEndDate(endDate); clone.setEndHour(endHour); clone.setImportance(importance); clone.setInfoId(infoId); clone.setKeywords(keywords); clone.setName(getName()); clone.setPk(pk); clone.setStatus(status); clone.setTargetValidatorId(targetValidatorId); clone.setCloneId(cloneId); clone.setUpdateDate(updateDate); clone.setUpdaterId(updaterId); clone.setValidateDate(validateDate); clone.setValidatorId(validatorId); clone.setVersion(version); return clone; }
private boolean isVisible(PublicationDetail pubDetail) { return PublicationDetail.VALID.equals(pubDetail.getStatus()); }
/** Test of selectByFatherPK method, of class PublicationDAO. */ @Test public void testSelectByFatherPK_Connection_NodePK() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); NodePK fatherPK = new NodePK("110", "kmelia200"); Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK); assertNotNull(result); assertEquals(2, result.size()); Iterator<PublicationDetail> iter = result.iterator(); PublicationDetail detail = iter.next(); PublicationPK primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); detail = iter.next(); primaryKey = new PublicationPK("101", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Bart Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("01:10", detail.getBeginHour()); assertEquals("Contenu de la publication 2", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("101", detail.getCreatorId()); assertEquals("2ème publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("20:35", detail.getEndHour()); assertEquals(5, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 2", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 2", detail.getTitle()); } finally { connection.close(); } }
/** Test of changeInstanceId method, of class PublicationDAO. */ @Test public void testChangeInstanceId() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("100", "kmelia200"); PublicationDetail detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); String targetInstance = "kmelia" + RandomGenerator.getRandomInt(600); PublicationDAO.changeInstanceId(con, pk, targetInstance); pk = new PublicationPK("100", targetInstance); detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals(targetInstance, detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); } finally { connection.close(); } }
/** Test of selectByFatherPK method, of class PublicationDAO. */ @Test public void testSelectByFatherPK_5args() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); NodePK fatherPK = new NodePK("110", "kmelia200"); String sorting = null; boolean filterOnVisibilityPeriod = false; String userId = "100"; Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId); assertNotNull(result); assertEquals(1, result.size()); Iterator<PublicationDetail> iter = result.iterator(); PublicationDetail detail = iter.next(); PublicationPK primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); filterOnVisibilityPeriod = true; result = PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId); assertNotNull(result); assertEquals(1, result.size()); iter = result.iterator(); detail = iter.next(); primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); } finally { connection.close(); } }
private void processMailContent( PublicationDetail pubDetail, File file, ImportReportManager reportManager, UnitReport unitReport, GEDImportExport gedIE, boolean isVersioningUsed) throws ImportExportException { String componentId = gedIE.getCurrentComponentId(); UserDetail userDetail = gedIE.getCurentUserDetail(); MailExtractor extractor = null; Mail mail = null; try { extractor = Extractor.getExtractor(file); mail = extractor.getMail(); } catch (Exception e) { SilverTrace.error( "importExport", "RepositoriesTypeManager.processMailContent", "importExport.EX_CANT_EXTRACT_MAIL_DATA", e); } if (mail != null) { // save mail data into dedicated form String content = mail.getBody(); PublicationContentType pubContent = new PublicationContentType(); XMLModelContentType modelContent = new XMLModelContentType("mail"); pubContent.setXMLModelContentType(modelContent); List<XMLField> fields = new ArrayList<XMLField>(); modelContent.setFields(fields); XMLField subject = new XMLField("subject", mail.getSubject()); fields.add(subject); XMLField body = new XMLField("body", ESCAPE_ISO8859_1.translate(content)); fields.add(body); XMLField date = new XMLField("date", DateUtil.getOutputDateAndHour(mail.getDate(), "fr")); fields.add(date); InternetAddress address = mail.getFrom(); String from = ""; if (StringUtil.isDefined(address.getPersonal())) { from += address.getPersonal() + " - "; } from += "<a href=\"mailto:" + address.getAddress() + "\">" + address.getAddress() + "</a>"; XMLField fieldFROM = new XMLField("from", from); fields.add(fieldFROM); Address[] recipients = mail.getAllRecipients(); String to = ""; for (Address recipient : recipients) { InternetAddress ia = (InternetAddress) recipient; if (StringUtil.isDefined(ia.getPersonal())) { to += ia.getPersonal() + " - "; } to += "<a href=\"mailto:" + ia.getAddress() + "\">" + ia.getAddress() + "</a></br>"; } XMLField fieldTO = new XMLField("to", to); fields.add(fieldTO); // save form gedIE.createPublicationContent( reportManager, unitReport, Integer.parseInt(pubDetail.getPK().getId()), pubContent, userDetail.getId(), null); // extract each file from mail... try { List<AttachmentDetail> documents = new ArrayList<AttachmentDetail>(); List<MailAttachment> attachments = extractor.getAttachments(); for (MailAttachment attachment : attachments) { if (attachment != null) { AttachmentDetail attDetail = new AttachmentDetail(); AttachmentPK pk = new AttachmentPK("unknown", "useless", componentId); attDetail.setLogicalName(attachment.getName()); attDetail.setPhysicalName(attachment.getPath()); attDetail.setAuthor(userDetail.getId()); attDetail.setSize(attachment.getSize()); attDetail.setPK(pk); documents.add(attDetail); } } // ... and save it if (isVersioningUsed) { // versioning mode VersioningImportExport versioningIE = new VersioningImportExport(userDetail); versioningIE.importDocuments( pubDetail.getPK().getId(), componentId, documents, Integer.parseInt(userDetail.getId()), pubDetail.isIndexable()); } else { // classic mode AttachmentImportExport attachmentIE = new AttachmentImportExport(); attachmentIE.importAttachments( pubDetail.getPK().getId(), componentId, documents, userDetail.getId(), pubDetail.isIndexable()); } } catch (Exception e) { SilverTrace.error( "importExport", "RepositoriesTypeManager.processMailContent", "root.EX_NO_MESSAGE", e); } } }
private PublicationDetail importFile( File file, ImportReportManager reportManager, MassiveReport massiveReport, GEDImportExport gedIE, PdcImportExport pdcIE, ImportSettings settings) { SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_ENTER_METHOD", "file = " + file.getName()); String componentId = gedIE.getCurrentComponentId(); UserDetail userDetail = gedIE.getCurentUserDetail(); PublicationDetail pubDetailToCreate = null; try { // Création du rapport unitaire UnitReport unitReport = new UnitReport(); massiveReport.addUnitReport(unitReport); // Check the file size ResourceLocator uploadSettings = new ResourceLocator("org.silverpeas.util.uploads.uploadSettings", ""); long maximumFileSize = uploadSettings.getLong("MaximumFileSize", 10485760); long fileSize = file.length(); if (fileSize <= 0L) { unitReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_FILE); reportManager.addNumberOfFilesNotImported(1); return pubDetailToCreate; } else if (fileSize > maximumFileSize) { unitReport.setError(UnitReport.ERROR_FILE_SIZE_EXCEEDS_LIMIT); reportManager.addNumberOfFilesNotImported(1); return pubDetailToCreate; } // On récupére les infos nécéssaires à la création de la publication pubDetailToCreate = PublicationImportExport.convertFileInfoToPublicationDetail(file, settings); pubDetailToCreate.setPk(new PublicationPK("unknown", "useless", componentId)); if ((settings.isDraftUsed() && pdcIE.isClassifyingMandatory(componentId)) || settings.isDraftUsed()) { pubDetailToCreate.setStatus(PublicationDetail.DRAFT); pubDetailToCreate.setStatusMustBeChecked(false); } SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_PARAM_VALUE", "pubDetailToCreate.status = " + pubDetailToCreate.getStatus()); // Création de la publication pubDetailToCreate = gedIE.createPublicationForMassiveImport(unitReport, pubDetailToCreate, settings); unitReport.setLabel(pubDetailToCreate.getPK().getId()); SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_PARAM_VALUE", "pubDetailToCreate created"); if (FileUtil.isMail(file.getName())) { // if imported file is an e-mail, its textual content is saved in a dedicated form // and attached files are attached to newly created publication processMailContent( pubDetailToCreate, file, reportManager, unitReport, gedIE, settings.isVersioningUsed()); } // add attachment SimpleDocument document; SimpleDocumentPK pk = new SimpleDocumentPK(null, componentId); if (settings.isVersioningUsed()) { document = new HistorisedDocument(); document.setPublicDocument( settings.getVersionType() == DocumentVersion.TYPE_PUBLIC_VERSION); } else { document = new SimpleDocument(); } document.setPK(pk); document.setFile(new SimpleAttachment()); document.setFilename(file.getName()); document.setSize(fileSize); document.getFile().setCreatedBy(userDetail.getId()); if (settings.useFileDates()) { document.setCreated(pubDetailToCreate.getCreationDate()); if (pubDetailToCreate.getUpdateDate() != null) { document.setUpdated(pubDetailToCreate.getUpdateDate()); } } else { document.setCreated(new Date()); } document.setForeignId(pubDetailToCreate.getPK().getId()); document.setContentType(FileUtil.getMimeType(file.getName())); AttachmentServiceFactory.getAttachmentService() .createAttachment(document, file, pubDetailToCreate.isIndexable(), false); reportManager.addNumberOfFilesProcessed(1); reportManager.addImportedFileSize(document.getSize(), componentId); } catch (Exception ex) { massiveReport.setError(UnitReport.ERROR_ERROR); SilverTrace.error( "importExport", "RepositoriesTypeManager.importFile", "root.EX_NO_MESSAGE", ex); } return pubDetailToCreate; }
/** Test of selectByNameAndNodeId method, of class PublicationDAO. */ @Test public void testSelectByNameAndNodeId() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pubPK = new PublicationPK("100", "kmelia200"); String name = "Publication 1"; int nodeId = 110; PublicationDetail result = PublicationDAO.selectByNameAndNodeId(con, pubPK, name, nodeId); assertEquals(pubPK, result.getPK()); assertEquals("Homer Simpson", result.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(result.getBeginDate())); assertEquals("00:00", result.getBeginHour()); assertEquals("Contenu de la publication 1", result.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(result.getCreationDate())); assertEquals("100", result.getCreatorId()); assertEquals("Première publication de test", result.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(result.getEndDate())); assertEquals("23:59", result.getEndHour()); assertEquals(1, result.getImportance()); assertEquals("0", result.getInfoId()); assertEquals("kmelia200", result.getInstanceId()); assertEquals("test", result.getKeywords()); assertEquals("Publication 1", result.getName()); assertEquals("Valid", result.getStatus()); assertEquals("300", result.getValidatorId()); assertEquals("Publication 1", result.getTitle()); } finally { connection.close(); } }
/** Test of insertRow method, of class PublicationDAO. */ @Test public void testInsertRow() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("500", "kmelia36"); Calendar now = Calendar.getInstance(); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.HOUR_OF_DAY, 0); Calendar beginDate = RandomGenerator.getCalendarAfter(now); Calendar endDate = RandomGenerator.getCalendarAfter(beginDate); String name = RandomGenerator.getRandomString(); String description = RandomGenerator.getRandomString(); String creatorId = "" + RandomGenerator.getRandomInt(); int importance = RandomGenerator.getRandomInt(5); String version = RandomGenerator.getRandomString(); String contenu = RandomGenerator.getRandomString(); StringBuilder buffer = new StringBuilder(); int nbKeywords = RandomGenerator.getRandomInt(5) + 2; for (int i = 0; i < nbKeywords; i++) { buffer.append(RandomGenerator.getRandomString()); if (i < (nbKeywords - 1)) { buffer.append(' '); } } String keywords = buffer.toString(); PublicationDetail detail = new PublicationDetail( pk, name, description, now.getTime(), beginDate.getTime(), endDate.getTime(), creatorId, importance, version, keywords, contenu); detail.setBeginHour(DateUtil.formatTime(beginDate)); detail.setEndHour(DateUtil.formatTime(endDate)); PublicationDAO.insertRow(con, detail); PublicationDetail result = PublicationDAO.loadRow(con, pk); detail.setUpdateDate(now.getTime()); detail.setUpdaterId(creatorId); detail.setInfoId("0"); assertEquals(detail.getPK(), result.getPK()); assertEquals(detail.getAuthor(), result.getAuthor()); assertEquals(detail.getBeginDate(), result.getBeginDate()); assertEquals(detail.getBeginHour(), result.getBeginHour()); assertEquals(detail.getContent(), result.getContent()); assertEquals(detail.getCreationDate(), result.getCreationDate()); assertEquals(detail.getUpdateDate(), result.getCreationDate()); assertEquals(detail.getCreatorId(), result.getCreatorId()); assertEquals(detail.getDescription(), result.getDescription()); assertEquals(detail.getEndDate(), result.getEndDate()); assertEquals(detail.getEndHour(), result.getEndHour()); assertEquals(detail.getImportance(), result.getImportance()); assertEquals(detail.getInfoId(), result.getInfoId()); assertEquals(detail.getInstanceId(), result.getInstanceId()); assertEquals(detail.getKeywords(), result.getKeywords()); assertEquals(detail.getName(), result.getName()); assertEquals(detail.getStatus(), result.getStatus()); assertEquals(detail.getTitle(), result.getTitle()); } finally { connection.close(); } }
/** Test of storeRow method, of class PublicationDAO. */ @Test public void testStoreRow() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("100", "kmelia200"); PublicationDetail detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); Calendar now = Calendar.getInstance(); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.HOUR_OF_DAY, 0); Calendar beginDate = RandomGenerator.getCalendarAfter(now); Calendar endDate = RandomGenerator.getCalendarAfter(beginDate); String name = RandomGenerator.getRandomString(); String description = RandomGenerator.getRandomString(); String creatorId = "" + RandomGenerator.getRandomInt(); int importance = RandomGenerator.getRandomInt(5); String version = RandomGenerator.getRandomString(); String contenu = RandomGenerator.getRandomString(); StringBuilder buffer = new StringBuilder(); int nbKeywords = RandomGenerator.getRandomInt(5) + 2; for (int i = 0; i < nbKeywords; i++) { buffer.append(RandomGenerator.getRandomString()); if (i < (nbKeywords - 1)) { buffer.append(' '); } } String keywords = buffer.toString(); detail.setName(name); detail.setDescription(description); detail.setCreationDate(now.getTime()); detail.setBeginDateAndHour(beginDate.getTime()); detail.setEndDateAndHour(endDate.getTime()); detail.setCreatorId(creatorId); detail.setImportance(importance); detail.setVersion(version); detail.setKeywords(keywords); detail.setContent(contenu); detail.setBeginHour(DateUtil.formatTime(beginDate)); detail.setEndHour(DateUtil.formatTime(endDate)); PublicationDAO.storeRow(con, detail); PublicationDetail result = PublicationDAO.loadRow(con, pk); detail.setUpdateDate(now.getTime()); detail.setUpdaterId(creatorId); detail.setInfoId("0"); assertEquals(detail.getPK(), result.getPK()); assertEquals(detail.getAuthor(), result.getAuthor()); assertEquals(detail.getBeginDate(), result.getBeginDate()); assertEquals(detail.getBeginHour(), result.getBeginHour()); assertEquals(detail.getContent(), result.getContent()); assertEquals(detail.getCreationDate(), result.getCreationDate()); assertEquals(detail.getUpdateDate(), result.getCreationDate()); assertEquals(detail.getCreatorId(), result.getCreatorId()); assertEquals(detail.getDescription(), result.getDescription()); assertEquals(detail.getEndDate(), result.getEndDate()); assertEquals(detail.getEndHour(), result.getEndHour()); assertEquals(detail.getImportance(), result.getImportance()); assertEquals(detail.getInfoId(), result.getInfoId()); assertEquals(detail.getInstanceId(), result.getInstanceId()); assertEquals(detail.getKeywords(), result.getKeywords()); assertEquals(detail.getName(), result.getName()); assertEquals(detail.getStatus(), result.getStatus()); assertEquals(detail.getTitle(), result.getTitle()); } finally { connection.close(); } }