List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
From source file:no.imr.stox.datastorage.DATRASDataStorage.java
public static void asTable(List<MissionBO> list, Integer level, Writer wr) { switch (level) { case 1://from ww w . j a v a 2 s .c om ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv("RecordType", "Quarter", "Country", "Ship", "Gear", "SweepLngt", "GearExp", "DoorType", "StNo", "HaulNo", "Year", "Month", "Day", "TimeShot", "Stratum", "HaulDur", "DayNight", "ShootLat", "ShootLong", "HaulLat", "HaulLong", "StatRec", "Depth", "HaulVal", "HydroStNo", "StdSpecRecCode", "BycSpecRecCode", "DataType", "Netopening", "Rigging", "Tickler", "Distance", "Warpingt", "Warpdia", "WarpDen", "DoorSurface", "DoorWgt", "DoorSpread", "WingSpread", "Buoyancy", "KiteDim", "WgtGroundRope", "TowDir", "GroundSpeed", "SpeedWater", "SurCurDir", "SurCurSpeed", "BotCurDir", "BotCurSpeed", "WindDir", "WindSpeed", "SwellDir", "SwellHeight", "SurTemp", "BotTemp", "SurSal", "BotSal", "ThermoCline", "ThClineDepth"))); for (MissionBO ms : list) { for (FishstationBO fs : ms.getFishstationBOs()) { Integer sweep = getGOVSweepByEquipment(fs.bo().getGear()); if (sweep == null) { // Sweep filter // other gears have sweep == null... continue; } // Filter other station types that blank (vanlig) if (!(fs.bo().getStationtype() == null || fs.bo().getStationtype().equals(""))) { continue; } if (fs.bo().getStationstartdate() == null) { continue; } Integer year = IMRdate.getYear(fs.bo().getStationstartdate()); Integer month = IMRdate.getMonth(fs.bo().getStationstartdate()); Integer day = IMRdate.getDayOfMonth(fs.bo().getStationstartdate()); Integer quarter = (month - 1) / 3 + 1; // Invalid also less/more than 5..90 min. og uten for 62 grader, evt kvartal. String haulVal = (fs.bo().getGearcondition() == null || fs.bo().getGearcondition().equals("1") || fs.bo().getGearcondition().equals("2")) && (fs.bo().getSamplequality() == null || fs.bo().getSamplequality().equals("0") || fs.bo().getSamplequality().equals("1")) ? "V" : "I"; ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv(// RecordType "HH", // Quarter quarter, // Country getTSCountryByIOC(fs.bo().getNation()), //TODO reference list // Ship getTSShipByPlatform(fs.bo().getCatchplatform()), // TODO reference list // Gear "GOV", // TODO reference list // SweepLngth sweep, // GearExp getGearExp(sweep, fs.getMission().bo().getStartyear(), fs.bo().getSerialnumber(), fs.bo().getBottomdepthstart()), // TODO: S=Single, D=Double, -9 not given // DoorType "P", fs.bo().getSerialnumber(), // HaulNo fs.bo().getStation(), // Year year, // Month month, // Day day, // TimeShot StringUtils.leftPad(IMRdate.formatTime(fs.bo().getStationstarttime(), "HHmm"), 4, '0'), // Stratum -9, // HaulDur Math.round(IMRdate.minutesDiffD( IMRdate.encodeLocalDateTime(fs.bo().getStationstartdate(), fs.bo().getStationstarttime()), IMRdate.encodeLocalDateTime(fs.bo().getStationstopdate(), fs.bo().getStationstoptime()))), // DayNight // 15 minutes before official sunrise, 15 min after official sunset. IMRdate.isDayTime( IMRdate.encodeLocalDateTime(fs.bo().getStationstartdate(), fs.bo().getStationstarttime()), fs.bo().getLatitudestart(), fs.bo().getLongitudestart()) ? "D" : "N", // ShootLat unkD(fs.bo().getLatitudestart(), "0.0000"), // ShootLong unkD(fs.bo().getLongitudestart(), "0.0000"), // HaulLat unkD(fs.bo().getLatitudeend(), "0.0000"), // HaulLong unkD(fs.bo().getLongitudeend(), "0.0000"), // StatRec AreaUnits.getFDOmrLokFromPos(fs.bo().getLatitudestart(), fs.bo().getLongitudestart()), // Depth Math.round(fs.bo().getBottomdepthstart()), //HaulVal haulVal, // TODO stasjon : match p logg mot toktlogger 5 nm, tid. // , DoorSpread, fra Biotic, Warplngth=wire, TowDir // HydroStNo -9, // StdSpecRecCode 1, // BycSpecRecCode 1, // DataType "R", unkD(fs.bo().getVerticaltrawlopening(), "0.0"), // Rigging -9, // Tickler -9, // Distance unkO(fs.bo().getDistance() != null ? fs.bo().getDistance() * 1852 : null), // Warplngt unkO(fs.bo().getWirelength()), //Warpdia -9, //Warpden -9, //Doorsurface 4.46, //DoorWgt 1075, //DoorSpread unkD(fs.bo().getTrawldoorspread(), "0.0"), //WingSpread -9, //Buoyancy -9, //KiteDim 0.85, //WgtGroundRope -9, // Tow dir unkO(fs.bo().getDirection() != null ? Math.round(fs.bo().getDirection()) : null), // Ground speed (speed of trawl over ground) unkD((fs.bo().getVesselspeed() == null ? fs.bo().getGearflow() : fs.bo().getVesselspeed()), "0.0"), //Speed water -9, //SurCurDir -9, //SurCurSpeed -9, //BotCurDir -9, //BotCurSpeed -9, //WinDir -9, //WindSpeed -9, //SwellDir -9, //SwellHeight -9, //SurTemp -9, //BotTemp -9, //SurSal -9, //BotSal -9, //ThermoCline -9, //ThClineDepth -9))); } } break; case 2: ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv("RecordType", "Quarter", "Country", "Ship", "Gear", "SweepLngt", "GearExp", "DoorType", "StNo", "HaulNo", "Year", "SpecCodeType", "SpecCode", "SpecVal", "Sex", "TotalNo", "CatIdentifier", "NoMeas", "SubFactor", "SubWgt", "CatCatchWgt", "LngtCode", "LngtClass", "HLNoAtLngt"))); for (MissionBO ms : list) { for (FishstationBO fs : ms.getFishstationBOs()) { Integer sweep = getGOVSweepByEquipment(fs.bo().getGear()); if (sweep == null) { // Sweep filter continue; } if (fs.bo().getStationstartdate() == null) { continue; } Integer year = IMRdate.getYear(fs.bo().getStationstartdate()); Integer month = IMRdate.getMonth(fs.bo().getStationstartdate()); Integer quarter = (int) Math.ceil(month / 3.0); String haulVal = (fs.bo().getGearcondition() == null || fs.bo().getGearcondition().equals("1") || fs.bo().getGearcondition().equals("2")) && (fs.bo().getSamplequality() == null || fs.bo().getSamplequality().equals("0") || fs.bo().getSamplequality().equals("1")) ? "V" : "I"; for (CatchSampleBO s : fs.getCatchSampleBOs()) { // IU: Sometimes we get null aphia if (s.bo().getAphia() == null) { continue; } // IU: Use aphia for comparison and add crustacean boolean boolean isHerringOrSprat = s.bo().getAphia().equals("126417") || s.bo().getAphia().equals("126425"); List<String> crustList = Arrays.asList("107275", "107276", "107369", "107253", "107703", "107704", "107350", "107254", "107205", "140712", "140687", "140658"); boolean isCrustacean = crustList.contains(s.bo().getAphia()); //Double raiseFac = 60.0 / IMRdate.minutesDiffD(IMRdate.encodeLocalDateTime(fs.bo().getStationstartdate(), fs.bo().getStationstarttime()), IMRdate.encodeLocalDateTime(fs.bo().getStationstopdate(), fs.bo().getStationstoptime())); MatrixBO hlNoAtLngth = new MatrixBO(); MatrixBO lsCountTot = new MatrixBO(); //Double sampleFac = s.getCatchcount().doubleValue() / s.getLengthsamplecount(); //if (s.getIndividualweight() == null || s.getCatchcount() == null) { // continue; //} Integer specVal = haulVal.equals("I") ? 0 : s.bo().getCatchcount() != null && s.bo().getLengthsamplecount() != null && s.bo().getCatchweight() != null ? 1 : s.bo().getCatchcount() != null && s.bo().getLengthsamplecount() == null && s.bo().getCatchweight() == null ? 4 : s.bo().getCatchcount() == null && s.bo().getLengthsamplecount() == null && s.bo().getCatchweight() != null ? 6 : s.bo().getCatchcount() != null && s.bo() .getLengthsamplecount() == null && s.bo() .getCatchweight() != null ? 7 : haulVal .equals("V") && s.bo() .getCatchcount() == null && s.bo() .getLengthsamplecount() == null && s.bo() .getCatchweight() == null ? 5 : s.bo().getCatchcount() != null && s.bo() .getLengthsamplecount() != null && s.bo() .getCatchweight() == null ? 0 : -9; String lngtCode = s.bo().getSampletype() != null ? isCrustacean ? "."/*1mm*/ : isHerringOrSprat ? "0"/*5mm*/ : "1" /*1cm*/ : "-9"/*1cm*/; Integer lenInterval = lngtCode.equals("0") ? 5 : 1; Boolean reportInMM = !lngtCode.equals("1"); Double catCatchWgt = (s.bo().getCatchweight() != null ? s.bo().getCatchweight() : 0) * 1000; // If weight is below 1, raise it into 1 if (catCatchWgt < 1 && catCatchWgt > 0) { catCatchWgt = Math.ceil(catCatchWgt) * 1.0; } Double subWeight = (s.bo().getLengthsampleweight() != null ? s.bo().getLengthsampleweight() : 0) * 1000; // If weight is below 1, raise it into 1 if (subWeight < 1 && subWeight > 0) { subWeight = Math.ceil(subWeight) * 1.0; } if (s.getIndividualBOs().isEmpty() || s.bo().getLengthsampleweight() == null) { String lngtClass = "-9"; String sex = "-9"; hlNoAtLngth.addGroupRowColValue(s.bo().getAphia(), sex, lngtClass, (s.bo().getCatchcount() != null ? s.bo().getCatchcount() : 0) * 1.0); lsCountTot.addGroupRowColValue(s.bo().getAphia(), sex, lngtClass, (s.bo().getLengthsamplecount() != null ? s.bo().getLengthsamplecount() : 0) * 1.0); } else { //if (s.bo().getlengthsampleweight() == null) { // continue; //} Double sampleFac = s.bo().getCatchweight() / s.bo().getLengthsampleweight(); for (IndividualBO i : s.getIndividualBOs()) { Double length = i.bo().getLength(); /*cm*/; if (i.bo().getLength() == null) { continue; } if (reportInMM) { if (length > 0) { length *= 10; } } else { // Some species have very small length in cm, use mm instead if (length < 1) { lngtCode = "."; lenInterval = 1; length *= 10; reportInMM = true; } } String lngtClass = "" + ImrMath.trunc(length, lenInterval.doubleValue()); String sex = i.bo().getSex() == null || i.bo().getSex().trim().isEmpty() ? "-9" : i.bo().getSex().equals("1") ? "F" : "M"; hlNoAtLngth.addGroupRowColValue(s.bo().getAphia(), sex, lngtClass, 1.0 * sampleFac); lsCountTot.addGroupRowColValue(s.bo().getAphia(), sex, lngtClass, 1.0); } } // Group Sex and Length class and report counts at catch level (raw) String aphia = (String) s.bo().getAphia(); for (String sex : hlNoAtLngth.getGroupRowKeys(aphia)) { Double totalNo = hlNoAtLngth.getGroupRowValueAsMatrix(aphia, sex).getSum(); Double noMeas = lsCountTot.getGroupRowValueAsMatrix(aphia, sex).getSum(); Double subFactor = (totalNo != 0 && noMeas != 0) ? totalNo / noMeas : -9; // If subFactor == 1, we can use catCatchWgt if (subFactor == 1) { subWeight = catCatchWgt; } for (String lngtClass : hlNoAtLngth.getGroupRowColKeys(aphia, sex)) { ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv("HL", quarter, getTSCountryByIOC(fs.bo().getNation()), getTSShipByPlatform(fs.bo().getCatchplatform()), "GOV", sweep, "S", "P", fs.bo().getSerialnumber(), fs.bo().getStation(), year, "W", // Worms aphia, specVal, sex, totalNo == 0 ? -9 : unkD(totalNo, "0.00"), // n per Hour s.bo().getCatchpartnumber(), //CatIdentifier noMeas == 0 ? -9 : Math.round(noMeas), // n measured as individual unkD(subFactor, "0.0000"), // SubFactor subWeight == 0 ? -9 : Math.round(subWeight), catCatchWgt == 0 ? -9 : Math.round(catCatchWgt), /* g */ lngtCode, lngtClass, lsCountTot.getGroupRowColValueAsDouble(aphia, sex, lngtClass) > 0 ? unkD( lsCountTot.getGroupRowColValueAsDouble(aphia, sex, lngtClass), "0.00") : -9.00))); } } } } } break; case 3: ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv("RecordType", "Quarter", "Country", "Ship", "Gear", "SweepLngt", "GearExp", "DoorType", "StNo", "HaulNo", "Year", "SpecCodeType", "SpecCode", "AreaType", "AreaCode", "LngtCode", "LngtClass", "Sex", "Maturity", "PlusGr", "AgeRings", "CANoAtLngt", "IndWgt"))); for (MissionBO ms : list) { for (FishstationBO fs : ms.getFishstationBOs()) { Integer sweep = getGOVSweepByEquipment(fs.bo().getGear()); if (sweep == null) { // Sweep filter continue; } if (fs.bo().getStationstartdate() == null) { continue; } Integer year = IMRdate.getYear(fs.bo().getStationstartdate()); Integer month = IMRdate.getMonth(fs.bo().getStationstartdate()); Integer quarter = (int) Math.ceil(month / 3.0); String areaLoc = fs.bo().getArea() != null && fs.bo().getLocation() != null ? fs.bo().getArea() + fs.bo().getLocation() : ""; for (CatchSampleBO s : fs.getCatchSampleBOs()) { // IU: Sometimes we get null aphia if (s.bo().getAphia() == null) { continue; } // IU: Use aphia for comparison and add crustacean boolean boolean isHerringOrSprat = s.bo().getAphia().equals("126417") || s.bo().getAphia().equals("126425"); List<String> crustList = Arrays.asList("107275", "107276", "107369", "107253", "107703", "107704", "107350", "107254", "107205", "140712", "140687", "140658"); boolean isCrustacean = crustList.contains(s.bo().getAphia()); if (s.getIndividualBOs().isEmpty()) { continue; } MatrixBO nInd = new MatrixBO(); MatrixBO nWithWeight = new MatrixBO(); MatrixBO totWeight = new MatrixBO(); String lngtCode = s.bo().getSampletype() != null ? isCrustacean ? "."/*1mm*/ : isHerringOrSprat ? "0"/*5mm*/ : "1" /*1cm*/ : "-9"/*1cm*/; Integer lenInterval = lngtCode.equals("0") ? 5 : 1; Boolean reportInMM = !lngtCode.equals("1"); for (IndividualBO i : s.getIndividualBOs()) { Double length = i.bo().getLength(); /*cm*/; if (i.bo().getLength() == null) { continue; } if (reportInMM) { if (length > 0) { length *= 10; } } else { // Some species have very small length in cm, use mm instead if (length < 1) { lngtCode = "."; lenInterval = 1; length *= 10; reportInMM = true; } } String lngtClass = "" + ImrMath.trunc(length, lenInterval.doubleValue()); String sex = i.bo().getSex() == null || i.bo().getSex().trim().isEmpty() ? "-9" : i.bo().getSex().equals("1") ? "F" : "M"; String maturity = getDATRASMaturity(i); String age = i.getAge() != null ? i.getAge() + "" : "-9"; nInd.addGroupRowColCellValue(lngtClass, sex, maturity, age, 1.0); if (i.bo().getIndividualweight()/*g*/ != null) { nWithWeight.addGroupRowColCellValue(lngtClass, sex, maturity, age, 1.0); totWeight.addGroupRowColCellValue(lngtClass, sex, maturity, age, i.bo().getIndividualweight()); } } // Group Length class - Sex - Maturity - Age and report meanweight and category count at individual level for (String lngtClass : nInd.getKeys()) { for (String sex : nInd.getGroupRowKeys(lngtClass)) { for (String maturity : nInd.getGroupRowColKeys(lngtClass, sex)) { for (String age : nInd.getGroupRowColCellKeys(lngtClass, sex, maturity)) { Long n = Math.round(nInd.getGroupRowColCellValueAsDouble(lngtClass, sex, maturity, age)); Double nWithW = nWithWeight.getGroupRowColCellValueAsDouble(lngtClass, sex, maturity, age); Double totW = totWeight.getGroupRowColCellValueAsDouble(lngtClass, sex, maturity, age); Double meanW = null; if (nWithW != null) { meanW = totW / nWithW; } ImrIO.write(wr, ExportUtil.carrageReturnLineFeed(ExportUtil.csv("CA", quarter, getTSCountryByIOC(fs.bo().getNation()), getTSShipByPlatform(fs.bo().getCatchplatform()), "GOV", sweep, "S", "P", fs.bo().getSerialnumber(), fs.bo().getStation(), year, "W", // Worms s.bo().getAphia(), 0, areaLoc, lngtCode, lngtClass, sex, maturity, -9, age, n, unkD(meanW, "0.0")))); } } } } } } } } }
From source file:no.imr.stox.functions.acoustic.PgNapesIO.java
public static void export2(String cruise, String country, String callSignal, String path, String fileName, List<DistanceBO> distances, Double groupThickness, Integer freqFilter, String specFilter, boolean withZeros) { Set<Integer> freqs = distances.stream().flatMap(dist -> dist.getFrequencies().stream()) .map(FrequencyBO::getFreq).collect(Collectors.toSet()); if (freqFilter == null && freqs.size() == 1) { freqFilter = freqs.iterator().next(); }/*from w w w .j av a2s . c om*/ if (freqFilter == null) { System.out.println("Multiple frequencies, specify frequency filter as parameter"); return; } Integer freqFilterF = freqFilter; // ef.final List<String> acList = distances.parallelStream().flatMap(dist -> dist.getFrequencies().stream()) .filter(fr -> freqFilterF.equals(fr.getFreq())).map(f -> { DistanceBO d = f.getDistanceBO(); LocalDateTime sdt = LocalDateTime.ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC); Double intDist = d.getIntegrator_dist(); String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0"); String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0"); String hour = StringUtils.leftPad(sdt.getHour() + "", 2, "0"); String minute = StringUtils.leftPad(sdt.getMinute() + "", 2, "0"); String log = Conversion.formatDoubletoDecimalString(d.getLog_start(), "0.0"); String acLat = Conversion.formatDoubletoDecimalString(d.getLat_start(), "0.000"); String acLon = Conversion.formatDoubletoDecimalString(d.getLon_start(), "0.000"); return Stream .of(d.getNation(), d.getPlatform(), d.getCruise(), log, sdt.getYear(), month, day, hour, minute, acLat, acLon, intDist, f.getFreq(), f.getThreshold()) .map(o -> o == null ? "" : o.toString()).collect(Collectors.joining("\t")) + "\t"; }).collect(Collectors.toList()); String fil1 = path + "/" + fileName + ".txt"; acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Hour", "Min", "AcLat", "AcLon", "Logint", "Frequency", "Sv_threshold").collect(Collectors.joining("\t"))); try { Files.write(Paths.get(fil1), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } acList.clear(); // Acoustic values distances.stream().filter(d -> d.getPel_ch_thickness() != null) .flatMap(dist -> dist.getFrequencies().stream()).filter(fr -> freqFilterF.equals(fr.getFreq())) .forEachOrdered(f -> { try { Double groupThicknessF = Math.max(f.getDistanceBO().getPel_ch_thickness(), groupThickness); Map<String, Map<Integer, Double>> pivot = f.getSa().stream() .filter(s -> s.getCh_type().equals("P")).map(s -> new SAGroup(s, groupThicknessF)) .filter(s -> s.getSpecies() != null && (specFilter == null || specFilter.equals(s.getSpecies()))) // create pivot table: species (dim1) -> depth interval index (dim2) -> sum sa (group aggregator) .collect(Collectors.groupingBy(SAGroup::getSpecies, Collectors.groupingBy( SAGroup::getDepthGroupIdx, Collectors.summingDouble(SAGroup::sa)))); if (pivot.isEmpty() && specFilter != null && withZeros) { pivot.put(specFilter, new HashMap<>()); } Integer maxGroupIdx = pivot.entrySet().stream().flatMap(e -> e.getValue().keySet().stream()) .max(Integer::compare).orElse(null); if (maxGroupIdx == null) { return; } acList.addAll(pivot.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)) .flatMap(e -> { return IntStream.range(0, maxGroupIdx + 1).boxed().map(groupIdx -> { Double chUpDepth = groupIdx * groupThicknessF; Double chLowDepth = (groupIdx + 1) * groupThicknessF; Double sa = e.getValue().get(groupIdx); if (sa == null) { sa = 0d; } String res = null; if (withZeros || sa > 0d) { DistanceBO d = f.getDistanceBO(); String log = Conversion.formatDoubletoDecimalString(d.getLog_start(), "0.0"); LocalDateTime sdt = LocalDateTime .ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC); String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0"); String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0"); //String sas = String.format(Locale.UK, "%11.5f", sa); res = Stream .of(d.getNation(), d.getPlatform(), d.getCruise(), log, sdt.getYear(), month, day, e.getKey(), chUpDepth, chLowDepth, sa) .map(o -> o == null ? "" : o.toString()) .collect(Collectors.joining("\t")); } return res; }).filter(s -> s != null); }).collect(Collectors.toList())); } catch (Exception e) { e.printStackTrace(); } }); String fil2 = path + "/" + fileName + "Values.txt"; acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Species", "ChUppDepth", "ChLowDepth", "SA").collect(Collectors.joining("\t"))); try { Files.write(Paths.get(fil2), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:nu.yona.server.crypto.CryptoUtil.java
public static String getRandomDigits(int length) { SecureRandom random = CryptoUtil.getSecureRandomInstance(); return StringUtils.leftPad(Integer.toString(random.nextInt((int) Math.pow(10, length))), length, '0'); }
From source file:org.alfresco.module.org_alfresco_module_rm.freeze.FreezeServiceImpl.java
/** * Creates a hold using the given nodeRef and reason * * @param nodeRef the nodeRef which will be frozen * @param reason the reason why the record will be frozen * @return NodeRef of the created hold//ww w . ja va2s . co m */ private NodeRef createHold(NodeRef nodeRef, String reason) { // get the hold container final NodeRef filePlan = getFilePlanService().getFilePlan(nodeRef); NodeRef holdContainer = getFilePlanService().getHoldContainer(filePlan); // calculate the hold name int nextCount = getNextCount(holdContainer); String holdName = I18NUtil.getMessage(MSG_HOLD_NAME) + " " + StringUtils.leftPad(Integer.toString(nextCount), 10, "0"); // create hold return getHoldService().createHold(filePlan, holdName, reason, null); }
From source file:org.alfresco.module.org_alfresco_module_rm.transfer.TransferServiceImpl.java
/** * @see org.alfresco.module.org_alfresco_module_rm.transfer.TransferService#transfer(NodeRef, boolean) *///from w ww. ja v a 2s .com @Override public NodeRef transfer(NodeRef nodeRef, boolean isAccession) { ParameterCheck.mandatory("nodeRef", nodeRef); // Get the root rm node NodeRef root = filePlanService.getFilePlan(nodeRef); // Get the transfer object NodeRef transferNodeRef = (NodeRef) AlfrescoTransactionSupport.getResource(KEY_TRANSFER_NODEREF); if (transferNodeRef == null) { // Calculate a transfer name QName nodeDbid = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "node-dbid"); Long dbId = (Long) nodeService.getProperty(nodeRef, nodeDbid); String transferName = StringUtils.leftPad(dbId.toString(), 10, "0"); // Create the transfer object Map<QName, Serializable> transferProps = new HashMap<QName, Serializable>(2); transferProps.put(ContentModel.PROP_NAME, transferName); transferProps.put(PROP_TRANSFER_ACCESSION_INDICATOR, isAccession); // setup location property from disposition schedule DispositionAction da = dispositionService.getNextDispositionAction(nodeRef); if (da != null) { DispositionActionDefinition actionDef = da.getDispositionActionDefinition(); if (actionDef != null) { transferProps.put(PROP_TRANSFER_LOCATION, actionDef.getLocation()); } } NodeRef transferContainer = filePlanService.getTransferContainer(root); transferNodeRef = nodeService.createNode(transferContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(RM_URI, transferName), TYPE_TRANSFER, transferProps).getChildRef(); // Bind the hold node reference to the transaction AlfrescoTransactionSupport.bindResource(KEY_TRANSFER_NODEREF, transferNodeRef); } else { // ensure this node has not already in the process of being transferred List<ChildAssociationRef> transferredAlready = nodeService.getChildAssocs(transferNodeRef, ASSOC_TRANSFERRED, ASSOC_TRANSFERRED); for (ChildAssociationRef car : transferredAlready) { if (car.getChildRef().equals(nodeRef)) { throw new AlfrescoRuntimeException( I18NUtil.getMessage(MSG_NODE_ALREADY_TRANSFER, nodeRef.toString())); } } } // Link the record to the trasnfer object nodeService.addChild(transferNodeRef, nodeRef, ASSOC_TRANSFERRED, ASSOC_TRANSFERRED); // Set PDF indicator flag setPDFIndicationFlag(transferNodeRef, nodeRef); // Set the transferring indicator aspect nodeService.addAspect(nodeRef, ASPECT_TRANSFERRING, null); if (isRecordFolder(nodeRef)) { // add the transferring indicator aspect to all the child records for (NodeRef record : recordService.getRecords(nodeRef)) { nodeService.addAspect(record, ASPECT_TRANSFERRING, null); } } return transferNodeRef; }
From source file:org.alfresco.repo.virtual.ref.NodeRefRadixHasher.java
@Override public NodeRef lookup(Pair<String, String> hash) { String storeHash = hash.getFirst(); String storeProtocolHash = storeHash.substring(0, 1); String storeIdHash = storeHash.substring(1, 2); String storeProtocol = storeProtocolStore.lookup(storeProtocolHash); String storeId = storeIdStore.lookup(storeIdHash); if (storeProtocol == null || storeId == null) { throw new RuntimeException("Lookup found no protocol or id for " + storeHash); }/*from w w w . j a v a 2 s . co m*/ BigInteger nodeId = new BigInteger(hash.getSecond(), radix); String nodeIdHexa = nodeId.toString(16); nodeIdHexa = StringUtils.leftPad(nodeIdHexa, 32, "0"); int leadZeros = 32 - nodeIdHexa.length(); if (leadZeros > 0) { } String groups[] = new String[5]; groups[0] = nodeIdHexa.substring(0, 8); groups[1] = nodeIdHexa.substring(8, 12); groups[2] = nodeIdHexa.substring(12, 16); groups[3] = nodeIdHexa.substring(16, 20); groups[4] = nodeIdHexa.substring(20, 32); StringBuilder idBuilder = new StringBuilder(groups[0]); for (int i = 1; i < groups.length; i++) { idBuilder.append("-"); idBuilder.append(groups[i]); } return new NodeRef(storeProtocol, storeId, idBuilder.toString()); }
From source file:org.alfresco.test.wqs.web.blog.BlogComponent.java
@Test(groups = { "WQS" }) public void AONE_5679() throws Exception { String visitorName = "name" + getTestName(); String visitorEmail = getTestName() + "@" + DOMAIN_FREE; String visitorWebsite = "website " + getTestName(); String visitorComment = "Comment by " + visitorName; // ---- Step 1 ---- // ---- Step action ---- // Navigate to http://host:8080/wcmqs // ---- Expected results ---- // Sample site is opened; navigateTo(wqsURL);//from w w w. j a v a 2s . com // ---- Step 2 ---- // ---- Step action ---- // Open any blog post; // ---- Expected results ---- // Blog post is opened; WcmqsHomePage homePage = new WcmqsHomePage(drone); homePage.selectMenu(WcmqsBlogPage.BLOG_MENU_STR); WcmqsBlogPage blogPage = new WcmqsBlogPage(drone); blogPage.clickLinkByTitle(WcmqsBlogPage.COMPANY_ORGANISES_WORKSHOP); WcmqsBlogPostPage wcmqsBlogPostPage = new WcmqsBlogPostPage(drone); // ---- Step 3 ---- // ---- Step action ---- // Enter too long data(more 1024 characters) in Name field; // ---- Expected results ---- // Data successfully entered; // TODO : Test CASE Steps needs to be updated since the data you enter // is automatically truncated to 70 chars wcmqsBlogPostPage.setVisitorName(visitorName + StringUtils.leftPad("test", 1100, 'a')); assertThat("Check if the number of entered chars is 70", wcmqsBlogPostPage.getVisitorName().length(), is(equalTo(70))); // ---- Step 4 ---- // ---- Step action ---- // Fill other fields with correct data and click Post button; // ---- Expected results ---- // You should be able to post succesfully; wcmqsBlogPostPage.setVisitorEmail(visitorEmail); wcmqsBlogPostPage.setVisitorWebsite(visitorWebsite); wcmqsBlogPostPage.setVisitorComment(visitorComment); wcmqsBlogPostPage.clickPostButton(); assertThat("Posting was succesfull", wcmqsBlogPostPage.isAddCommentMessageDisplay()); // ---- Step 5 ---- // ---- Step action ---- // Open any blog post again; // ---- Expected results ---- // Blog post is opened; homePage = new WcmqsHomePage(drone); homePage.selectMenu(WcmqsBlogPage.BLOG_MENU_STR); blogPage = new WcmqsBlogPage(drone); blogPage.clickLinkByTitle(WcmqsBlogPage.ETHICAL_FUNDS); assertThat("Verify if the correct page opened ", blogPage.getTitle(), containsString(WcmqsBlogPage.ETHICAL_FUNDS)); // ---- Step 6 ---- // ---- Step action ---- // Enter too long data(more 1024 characters) in Email field; // ---- Expected results ---- // Data successfully entered; // TODO : Test CASE Steps needs to be updated since the data you enter // is automatically truncated to 100 chars wcmqsBlogPostPage.setVisitorEmail(visitorEmail + StringUtils.leftPad("test", 1100, 'a')); assertThat("Check if the number of entered chars is 100", wcmqsBlogPostPage.getVisitorEmail().length(), is(equalTo(100))); // ---- Step 7 ---- // ---- Step action ---- // Fill other fields with correct data and click Post button; // ---- Expected results ---- // Comment is displayed, Email's field data is restricted to 101 // symbols; wcmqsBlogPostPage.setVisitorName(visitorName); wcmqsBlogPostPage.setVisitorWebsite(visitorWebsite); wcmqsBlogPostPage.setVisitorComment(visitorComment); wcmqsBlogPostPage.clickPostButton(); assertThat("Posting was succesfull", wcmqsBlogPostPage.isAddCommentMessageDisplay()); // ---- Step 8 ---- // ---- Step action ---- // Open any blog post again; // ---- Expected results ---- // Blog post is opened; homePage = new WcmqsHomePage(drone); homePage.selectMenu(WcmqsBlogPage.BLOG_MENU_STR); blogPage = new WcmqsBlogPage(drone); blogPage.clickLinkByTitle(WcmqsBlogPage.ANALYSTS_LATEST_THOUGHTS); assertThat("Verify if the correct page opened ", blogPage.getTitle(), containsString(WcmqsBlogPage.ANALYSTS_LATEST_THOUGHTS)); // ---- Step 9 ---- // ---- Step action ---- // Enter too long data(more 1024 characters) in Website field; // ---- Expected results ---- // Data successfully entered; // TODO : Test CASE Steps needs to be updated since the data you enter // is automatically truncated to 101 chars wcmqsBlogPostPage.setVisitorWebsite(visitorWebsite + StringUtils.leftPad("test", 1100, 'a')); assertThat("Check if the number of entered chars is 100", wcmqsBlogPostPage.getVisitorWebsite().length(), is(equalTo(100))); // ---- Step 10 ---- // ---- Step action ---- // Fill other fields with correct data and click Post button; // ---- Expected results ---- // Comment is displayed, Website's field data is restricted to 101 // symbols; wcmqsBlogPostPage.setVisitorName(visitorName); wcmqsBlogPostPage.setVisitorEmail(visitorEmail); wcmqsBlogPostPage.setVisitorComment(visitorComment); wcmqsBlogPostPage.clickPostButton(); assertThat("Posting was succesfull", wcmqsBlogPostPage.isAddCommentMessageDisplay()); }
From source file:org.apache.accumulo.monitor.rest.trace.TracesResource.java
protected Range getRangeForTrace(long minutesSince) { long endTime = System.currentTimeMillis(); long millisSince = minutesSince * 60 * 1000; // Catch the overflow if (millisSince < minutesSince) { millisSince = endTime;//from ww w.ja v a 2 s . c o m } long startTime = endTime - millisSince; String startHexTime = Long.toHexString(startTime), endHexTime = Long.toHexString(endTime); if (startHexTime.length() < endHexTime.length()) { StringUtils.leftPad(startHexTime, endHexTime.length(), '0'); } return new Range(new Text("start:" + startHexTime), new Text("start:" + endHexTime)); }
From source file:org.apache.axis2.transport.testkit.ManagedTestSuite.java
@Override public void addTest(Test test) { if (test instanceof ManagedTestCase) { ManagedTestCase ttest = (ManagedTestCase) test; Map<String, String> map = ttest.getNameComponents(); boolean excluded = false; for (FilterExpression exclude : excludes) { if (exclude.matches(map)) { excluded = true;// www . jav a 2s.c om break; } } if (excluded != invertExcludes) { return; } ttest.init(StringUtils.leftPad(String.valueOf(nextId++), 4, '0'), reuseResources, testClass); ttest.getResourceSet().resolve(); } super.addTest(test); }
From source file:org.apache.axis2.transport.testkit.util.LogManager.java
public synchronized OutputStream createLog(String name) throws IOException { testCaseDir.mkdirs();//from w w w .j av a2 s. c o m OutputStream log = new FileOutputStream(new File(testCaseDir, StringUtils.leftPad(String.valueOf(sequence++), 2, '0') + "-" + name + ".log")); logs.add(log); return log; }