List of usage examples for org.apache.commons.lang3.builder ReflectionToStringBuilder toString
public static String toString(final Object object)
Builds a toString
value using the default ToStringStyle
through reflection.
From source file:com.amazonaws.services.kinesis.stormspout.ShardInfo.java
@Override public String toString() { return ReflectionToStringBuilder.toString(this); }
From source file:cn.afterturn.easypoi.word.parse.excel.ExcelEntityParse.java
private int createCells(int index, Object t, List<ExcelExportEntity> excelParams, XWPFTable table, short rowHeight) { try {//from w w w.j a v a 2s. c o m ExcelExportEntity entity; XWPFTableRow row = table.insertNewTableRow(index); if (rowHeight != -1) { row.setHeight(rowHeight); } int maxHeight = 1, cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { Collection<?> list = (Collection<?>) entity.getMethod().invoke(t, new Object[] {}); int listC = 0; for (Object obj : list) { createListCells(index + listC, cellNum, obj, entity.getList(), table, rowHeight); listC++; } cellNum += entity.getList().size(); if (list != null && list.size() > maxHeight) { maxHeight = list.size(); } } else { Object value = getCellValue(entity, t); if (entity.getType() == 1) { setCellValue(row, value, cellNum++); } } } // ???? cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { cellNum += entity.getList().size(); } else if (entity.isNeedMerge() && maxHeight > 1) { table.setCellMargins(index, index + maxHeight - 1, cellNum, cellNum); cellNum++; } } return maxHeight; } catch (Exception e) { LOGGER.error("excel cell export error ,data is :{}", ReflectionToStringBuilder.toString(t)); throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e); } }
From source file:com.amazonaws.services.kinesis.stormspout.state.zookeeper.LocalShardState.java
private String detailedToString() { return ReflectionToStringBuilder.toString(this); }
From source file:gr.abiss.calipso.model.dto.ReportDataSet.java
public void addEntry(ReportDataEntry entry) { if (this.entries == null) { this.entries = new TreeSet<ReportDataEntry>(); }//from ww w .j av a 2 s. c o m LOGGER.info("Adding entry: " + ReflectionToStringBuilder.toString(entry)); this.entries.remove(entry); this.entries.add(entry); }
From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java
/** * ? Cells//from w ww .j ava 2 s.c om */ public int[] createCells(Drawing patriarch, int index, Object t, List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook, short rowHeight, int cellNum) { try { ExcelExportEntity entity; Row row = sheet.getRow(index) == null ? sheet.createRow(index) : sheet.getRow(index); if (rowHeight != -1) { row.setHeight(rowHeight); } int maxHeight = 1, listMaxHeight = 1; // ???? int margeCellNum = cellNum; int indexKey = createIndexCell(row, index, excelParams.get(0)); cellNum += indexKey; for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { Collection<?> list = getListCellValue(entity, t); int listIndex = 0, tmpListHeight = 0; if (list != null && list.size() > 0) { int tempCellNum = 0; for (Object obj : list) { int[] temp = createCells(patriarch, index + listIndex, obj, entity.getList(), sheet, workbook, rowHeight, cellNum); tempCellNum = temp[1]; tmpListHeight += temp[0]; listIndex++; } cellNum = tempCellNum; listMaxHeight = Math.max(listMaxHeight, tmpListHeight); } } else { Object value = getCellValue(entity, t); if (entity.getType() == BaseEntityTypeConstants.STRING_TYPE) { createStringCell(row, cellNum++, value == null ? "" : value.toString(), index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity); } else if (entity.getType() == BaseEntityTypeConstants.DOUBLE_TYPE) { createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity); } else { createImageCell(patriarch, entity, row, cellNum++, value == null ? "" : value.toString(), t); } if (entity.isHyperlink()) { row.getCell(cellNum - 1).setHyperlink(dataHandler.getHyperlink( row.getSheet().getWorkbook().getCreationHelper(), t, entity.getName(), value)); } } } maxHeight += listMaxHeight - 1; if (indexKey == 1 && excelParams.get(1).isNeedMerge()) { excelParams.get(0).setNeedMerge(true); } for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { margeCellNum += entity.getList().size(); } else if (entity.isNeedMerge() && maxHeight > 1) { for (int i = index + 1; i < index + maxHeight; i++) { if (sheet.getRow(i) == null) { sheet.createRow(i); } sheet.getRow(i).createCell(margeCellNum); sheet.getRow(i).getCell(margeCellNum).setCellStyle(getStyles(false, entity)); } PoiMergeCellUtil.addMergedRegion(sheet, index, index + maxHeight - 1, margeCellNum, margeCellNum); margeCellNum++; } } return new int[] { maxHeight, cellNum }; } catch (Exception e) { LOGGER.error("excel cell export error ,data is :{}", ReflectionToStringBuilder.toString(t)); LOGGER.error(e.getMessage(), e); throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e); } }
From source file:cn.afterturn.easypoi.excel.imports.base.ImportBaseService.java
/** * ??/*from w w w .j a va 2s. c om*/ * @param targetId * @param fields * @param excelParams * @param excelCollection * @param pojoClass * @param getMethods * @throws Exception */ public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods, ExcelEntity excelEntityAnn) throws Exception { ExcelImportEntity excelEntity = null; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { continue; } if (PoiPublicUtil.isCollection(field.getType())) { // ? ExcelCollection excel = field.getAnnotation(ExcelCollection.class); ExcelCollectionParams collection = new ExcelCollectionParams(); collection.setName(field.getName()); Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>(); ParameterizedType pt = (ParameterizedType) field.getGenericType(); Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0]; collection.setType(clz); getExcelFieldList(StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null); collection.setExcelParams(temp); collection.setExcelName(PoiPublicUtil .getValueByTargetId(field.getAnnotation(ExcelCollection.class).name(), targetId, null)); additionalCollectionName(collection); excelCollection.add(collection); } else if (PoiPublicUtil.isJavaClass(field) || field.getType().isEnum()) { addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams, excelEntityAnn); } else { List<Method> newMethods = new ArrayList<Method>(); if (getMethods != null) { newMethods.addAll(getMethods); } // newMethods.add(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); ExcelEntity excel = field.getAnnotation(ExcelEntity.class); if (excel.show() && StringUtils.isEmpty(excel.name())) { throw new ExcelImportException("if use ExcelEntity ,name mus has value ,data: " + ReflectionToStringBuilder.toString(excel), ExcelImportEnum.PARAMETER_ERROR); } getAllExcelField(StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods, excel); } } }
From source file:cn.afterturn.easypoi.excel.export.base.ExportCommonService.java
/** * ??// www . java 2s .c om * * @param targetId ID */ public void getAllExcelField(String[] exclusions, String targetId, Field[] fields, List<ExcelExportEntity> excelParams, Class<?> pojoClass, List<Method> getMethods, ExcelEntity excelGroup) throws Exception { List<String> exclusionsList = exclusions != null ? Arrays.asList(exclusions) : null; ExcelExportEntity excelEntity; // ??filed for (int i = 0; i < fields.length; i++) { Field field = fields[i]; // ?collection,?java,? if (PoiPublicUtil.isNotUserExcelUserThis(exclusionsList, field, targetId)) { continue; } // Excel ??? if (field.getAnnotation(Excel.class) != null) { Excel excel = field.getAnnotation(Excel.class); String name = PoiPublicUtil.getValueByTargetId(excel.name(), targetId, null); if (StringUtils.isNotBlank(name)) { excelParams.add(createExcelExportEntity(field, targetId, pojoClass, getMethods, excelGroup)); } } else if (PoiPublicUtil.isCollection(field.getType())) { ExcelCollection excel = field.getAnnotation(ExcelCollection.class); ParameterizedType pt = (ParameterizedType) field.getGenericType(); Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0]; List<ExcelExportEntity> list = new ArrayList<ExcelExportEntity>(); getAllExcelField(exclusions, StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId, PoiPublicUtil.getClassFields(clz), list, clz, null, null); excelEntity = new ExcelExportEntity(); excelEntity.setName(PoiPublicUtil.getValueByTargetId(excel.name(), targetId, null)); if (i18nHandler != null) { excelEntity.setName(i18nHandler.getLocaleName(excelEntity.getName())); } excelEntity.setOrderNum( Integer.valueOf(PoiPublicUtil.getValueByTargetId(excel.orderNum(), targetId, "0"))); excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); excelEntity.setList(list); excelParams.add(excelEntity); } else { List<Method> newMethods = new ArrayList<Method>(); if (getMethods != null) { newMethods.addAll(getMethods); } newMethods.add(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); ExcelEntity excel = field.getAnnotation(ExcelEntity.class); if (excel.show() && StringUtils.isEmpty(excel.name())) { throw new ExcelExportException("if use ExcelEntity ,name mus has value ,data: " + ReflectionToStringBuilder.toString(excel), ExcelExportEnum.PARAMETER_ERROR); } getAllExcelField(exclusions, StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, field.getType(), newMethods, excel.show() ? excel : null); } } }
From source file:cn.afterturn.easypoi.excel.imports.ExcelImportService.java
private <T> List<T> importExcel(Collection<T> result, Sheet sheet, Class<?> pojoClass, ImportParams params, Map<String, PictureData> pictures) throws Exception { List collection = new ArrayList(); Map<String, ExcelImportEntity> excelParams = new HashMap<String, ExcelImportEntity>(); List<ExcelCollectionParams> excelCollection = new ArrayList<ExcelCollectionParams>(); String targetId = null;/*w ww . ja v a 2 s.c o m*/ i18nHandler = params.getI18nHandler(); boolean isMap = Map.class.equals(pojoClass); if (!isMap) { Field[] fileds = PoiPublicUtil.getClassFields(pojoClass); ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); if (etarget != null) { targetId = etarget.value(); } getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null, null); } Iterator<Row> rows = sheet.rowIterator(); for (int j = 0; j < params.getTitleRows(); j++) { rows.next(); } Map<Integer, String> titlemap = getTitleMap(rows, params, excelCollection, excelParams); checkIsValidTemplate(titlemap, excelParams, params, excelCollection); Row row = null; Object object = null; String picId; int readRow = 1; // for (int i = 0; i < params.getStartRows(); i++) { rows.next(); } //index ?,? if (excelCollection.size() > 0 && params.getKeyIndex() == null) { params.setKeyIndex(0); } if (params.isConcurrentTask()) { ForkJoinPool forkJoinPool = new ForkJoinPool(); int endRow = sheet.getLastRowNum() - params.getLastOfInvalidRow(); if (params.getReadRows() > 0) { endRow = params.getReadRows(); } ExcelImportForkJoinWork task = new ExcelImportForkJoinWork( params.getStartRows() + params.getHeadRows() + params.getTitleRows(), endRow, sheet, params, pojoClass, this, targetId, titlemap, excelParams); ExcelImportResult forkJoinResult = forkJoinPool.invoke(task); collection = forkJoinResult.getList(); failCollection = forkJoinResult.getFailList(); } else { StringBuilder errorMsg; while (rows.hasNext() && (row == null || sheet.getLastRowNum() - row.getRowNum() > params.getLastOfInvalidRow())) { if (params.getReadRows() > 0 && readRow > params.getReadRows()) { break; } row = rows.next(); // Fix row if (sheet.getLastRowNum() - row.getRowNum() < params.getLastOfInvalidRow()) { break; } /* ?? */ if (row.getLastCellNum() < 0) { continue; } if (isMap && object != null) { ((Map) object).put("excelRowNum", row.getRowNum()); } errorMsg = new StringBuilder(); // ???,?,? // keyIndex ??,?? if (params.getKeyIndex() != null && (row.getCell(params.getKeyIndex()) == null || StringUtils.isEmpty(getKeyValue(row.getCell(params.getKeyIndex())))) && object != null) { for (ExcelCollectionParams param : excelCollection) { addListContinue(object, param, row, titlemap, targetId, pictures, params, errorMsg); } } else { object = PoiPublicUtil.createObject(pojoClass, targetId); try { Set<Integer> keys = titlemap.keySet(); for (Integer cn : keys) { Cell cell = row.getCell(cn); String titleString = (String) titlemap.get(cn); if (excelParams.containsKey(titleString) || isMap) { if (excelParams.get(titleString) != null && excelParams.get(titleString) .getType() == BaseEntityTypeConstants.IMAGE_TYPE) { picId = row.getRowNum() + "_" + cn; saveImage(object, picId, excelParams, titleString, pictures, params); } else { try { saveFieldValue(params, object, cell, excelParams, titleString, row); } catch (ExcelImportException e) { // ?,, if (params.isNeedVerify() && ExcelImportEnum.GET_VALUE_ERROR.equals(e.getType())) { errorMsg.append(" ").append(titleString) .append(ExcelImportEnum.GET_VALUE_ERROR.getMsg()); } } } } } //for (int i = row.getFirstCellNum(), le = titlemap.size(); i < le; i++) { //} if (object instanceof IExcelDataModel) { ((IExcelDataModel) object).setRowNum(row.getRowNum()); } for (ExcelCollectionParams param : excelCollection) { addListContinue(object, param, row, titlemap, targetId, pictures, params, errorMsg); } if (verifyingDataValidity(object, row, params, isMap, errorMsg)) { collection.add(object); } else { failCollection.add(object); } } catch (ExcelImportException e) { LOGGER.error("excel import error , row num:{},obj:{}", readRow, ReflectionToStringBuilder.toString(object)); if (!e.getType().equals(ExcelImportEnum.VERIFY_ERROR)) { throw new ExcelImportException(e.getType(), e); } } catch (Exception e) { LOGGER.error("excel import error , row num:{},obj:{}", readRow, ReflectionToStringBuilder.toString(object)); throw new RuntimeException(e); } } readRow++; } } return collection; }
From source file:com.ah.be.cloudauth.HmCloudAuthCertMgmtImpl.java
private void updateIDMCustomer(HmUser user) throws Exception { final String vhmEmail = user.getEmailAddress(); final HmDomain switchDomain = user.getSwitchDomain(); final boolean isSwitched = null != switchDomain; final HmDomain domain = isSwitched ? switchDomain : user.getOwner(); final String vhmID = domain.getVhmID(); LOG.info("updateIDMCustomer", "Update vHM[" + vhmID + "] for" + " the user:" + vhmEmail); // send request to portal LOG.info("updateIDMCustomer", "*** start send request to Portal to retrieve the vHM customer infomation. ***"); VHMCustomerInfo vhmCustomer = ClientUtils.getPortalResUtils() .getVHMCustomerInfo(isSwitched ? vhmID : vhmEmail); LOG.debug("updateIDMCustomer", "the response is " + ReflectionToStringBuilder.toString(vhmCustomer)); LOG.info("updateIDMCustomer", "*** end send request to Portal to retrieve the vHM customer infomation. ***"); if (null != vhmCustomer) { if (isSwitched) { // for the switch domain vhmCustomer.setEmail(vhmCustomer.getPrimaryEmail()); } else {// www . j a v a 2s . c om // for the normal vhmCustomer.setEmail(vhmEmail); } // update the status according the response LOG.info("updateIDMCustomer", "*** start update ID Manager status in database from response. ***"); CloudAuthCustomer idmCustomer = QueryUtil.findBoByAttribute(CloudAuthCustomer.class, "owner.id", domain.getId()); if (null == idmCustomer) { idmCustomer = new CloudAuthCustomer(vhmCustomer.getCustomerId(), vhmCustomer.getIdmID(), domain); QueryUtil.createBo(idmCustomer); } else { // avoid to update the same values idmCustomer.setCustomerId(vhmCustomer.getCustomerId()); idmCustomer.setIdmanagerId(vhmCustomer.getIdmID()); QueryUtil.updateBo(idmCustomer); } LOG.info("updateIDMCustomer", "*** end update ID Manager status in database from response. ***"); MgrUtil.setSessionAttribute(SessionKeys.VHM_CUSTOMER_INFO_KEY, vhmCustomer); } }
From source file:com.francetelecom.clara.cloud.activation.plugin.cf.infrastructure.CfAdapterImpl.java
@Override public void logAppDiagnostics(String appName, String spaceName) { CloudFoundryOperations cfClient = login(spaceName); try {//from www. j av a 2 s . c o m try { List<ApplicationLog> crashLogs = cfClient.getRecentLogs(appName); logger.info("Crashlogs for " + appName + " are:\n" + crashLogs); } catch (Exception e) { logger.info("Unable to log diagnostic details (crashlogs) for app=" + appName + ", caught:" + e, e); } try { String jonasLogDirPath = "app/.jonas_base/logs/"; String logsDirContent = cfClient.getFile(appName, 0, jonasLogDirPath); logger.info("logs dir content: \n{}", logsDirContent); String jonasLogFileName = getJonasLogFileName(new Date()); if (logsDirContent != null && logsDirContent.contains(jonasLogFileName)) { String jonasLogsContent = cfClient.getFile(appName, 0, jonasLogDirPath + jonasLogFileName); logger.info("jonasLogs Content: \n{}", jonasLogsContent); } } catch (Exception e) { logger.info("Unable to log diagnostic details (jonasLogs) for app=" + appName + ", caught:" + e); } try { String buildpackDiagnosticLogsPath = "app/.buildpack-diagnostics/buildpack.log"; String buildpackDiagnosticLogs = cfClient.getFile(appName, 0, buildpackDiagnosticLogsPath); logger.info("buildpackDiagnosticLogs content: \n{}", buildpackDiagnosticLogs); } catch (Exception e) { logger.info("Unable to log diagnostic details (buildpack diagnostic logs) for app=" + appName + ", caught:" + e); } try { ApplicationStats applicationStats = cfClient.getApplicationStats(appName); List<InstanceStats> records = applicationStats.getRecords(); int i = 0; for (InstanceStats record : records) { logger.info("Stats for instance #" + i + " of App " + appName + " are: " + ReflectionToStringBuilder.toString(record)); i++; } } catch (Exception e) { logger.info("Unable to log diagnostic details (app stats) for app=" + appName + ", caught:" + e, e); } } finally { cfClient.logout(); } }