/** * Returns all the versions that were checked in between two dates. * * @param startDate the start date * @param endDate the end date * @return an container of properties representing the versions between the specified dates * @throws JCaHarvestException */ private JCaContainer getVersionsInRange(Date startDate, Date endDate) throws JCaHarvestException { JCaContext context = harvest.getContext(); context.setProject(project); context.setState(state); JCaVersionChooser vc = context.getVersionChooser(); vc.clear(); vc.setRecursive(true); if (viewPath != null) { vc.setParentPath(viewPath); } vc.setVersionItemOption(itemOption); // Defaults to JCaConst.VERSION_FILTER_ITEM_BOTH vc.setVersionOption(versionOption); // Defaults to JCaConst.VERSION_FILTER_LATEST_IN_VIEW vc.setVersionStatusOption(statusOption); // Defaults to JCaConst.VERSION_FILTER_ALL_TAG vc.setBranchOption(branchOption); // Defaults to JCaConst.BRANCH_FILTER_TRUNK_ONLY vc.setVersionDateOption(JCaConst.VERSION_OPTION_DATE_BETWEEN); vc.setFromDate(convertDateToJCaTimeStamp(startDate)); vc.setToDate(convertDateToJCaTimeStamp(endDate)); vc.execute(); return vc.getVersionList(); }
/** * Returns all the versions that were promoted or demoted after the given date. * * @param startDate the start date * @return an container of properties representing the versions * @throws JCaHarvestException */ private JCaContainer getPromotedAndDemotedVersions(Date startDate, boolean promote) throws JCaHarvestException { JCaContext context = harvest.getContext(); context.setProject(project); context.setState(state); int[] pkgobjids = null; JCaSQL sql = context.getSQL(); if (promote) { sql.setSQLStatement( "SELECT DISTINCT packageObjId FROM harPkgHistory" + " WHERE environmentName='" + project + "'" + " AND stateName='" + state + "'" + " AND action='Promote'" + " AND execdTime > '" + convertDateToDatabaseDate(startDate) + "'"); } else { if (prevState.indexOf(",") != -1) { StringTokenizer tok = new StringTokenizer(prevState, ","); StringBuffer buf = new StringBuffer(); while (tok.hasMoreTokens()) { if (buf.length() > 0) { buf.append("','"); } buf.append(tok.nextToken()); } prevState = buf.toString(); } sql.setSQLStatement( " SELECT DISTINCT packageObjId FROM harPkgHistory" + " WHERE environmentName='" + project + "'" + " AND stateName IN ('" + prevState + "')" + " AND action='Demote'" + " AND execdTime > '" + convertDateToDatabaseDate(startDate) + "'"); } sql.execute(); JCaContainer sqlData = sql.getSQLResult(); if (sqlData.getKeyCount() > 0) { int count = sqlData.getKeyElementCount("PACKAGEOBJID"); if (count > 0) { pkgobjids = new int[count]; for (int n = 0; n < count; n++) { pkgobjids[n] = sqlData.getInt("PACKAGEOBJID", n); LOG.info("Package " + pkgobjids[n] + " has been " + (promote ? "promoted" : "demoted")); } } } if ((pkgobjids == null) || (pkgobjids.length == 0)) { return new JCaContainer(); } JCaVersionChooser vc = context.getVersionChooser(); vc.clear(); vc.setRecursive(true); if (viewPath != null) { vc.setParentPath(viewPath); } vc.setVersionItemOption(itemOption); // Defaults to JCaConst.VERSION_FILTER_ITEM_BOTH vc.setVersionOption(versionOption); // Defaults to JCaConst.VERSION_FILTER_LATEST_IN_VIEW vc.setVersionStatusOption(statusOption); // Defaults to JCaConst.VERSION_FILTER_ALL_TAG vc.setBranchOption(branchOption); // Defaults to JCaConst.BRANCH_FILTER_TRUNK_ONLY for (int n = 0; n < pkgobjids.length; n++) { vc.setPackageObjId(pkgobjids[n], n); } vc.execute(); return vc.getVersionList(); }