List of usage examples for java.util List toString
public String toString()
From source file:org.o3project.ocnrm.lib.flow.OduFlowCreatorTest.java
/** * Test method for/*from w w w. ja va 2 s. c o m*/ * {@link org.o3project.ocnrm.lib.flow.OduFlowCreator#createFlow()} */ @Test public void testCreateFlowWithJSONException() throws Exception { Logger dummyLogger = mock(Logger.class); Field field = target.getClass().getSuperclass().getSuperclass().getDeclaredField("logger"); field.setAccessible(true); field.set(target, dummyLogger); JSONParser parser = mock(JSONParser.class); PowerMockito.whenNew(JSONParser.class).withNoArguments().thenReturn(parser); OptFlow flow = new OptFlow(); flow.setTerminationPointPairs(new ArrayList<TerminationPoints>()); PowerMockito.doThrow(mock(JSONException.class)).when(parser).convertToJson(anyListOf(FlowData.class), eq(seqNo)); List<String> result = target.createFlow(flow, data, seqNo); assertThat(result.toString(), is("[]")); verify(dummyLogger, times(1)).error(seqNo + "\t" + "JSONException occured."); }
From source file:edu.stanford.junction.director.JAVADirector.java
private Process launchJAR(URL jarURL, URI activityURI) { final String JAR_PATH = "jars/"; String jarName = JAR_PATH + "/" + jarURL.getPath().substring(1).replace("/", "-"); File jarFile = new File(jarName); File tmpFile = new File(jarName + ".tmp"); if (!jarFile.exists() && !tmpFile.exists()) { try {// w w w .ja v a 2s . c o m FileOutputStream out = new FileOutputStream(tmpFile); InputStream in = jarURL.openStream(); byte[] buf = new byte[4 * 1024]; int bytesRead; while ((bytesRead = in.read(buf)) != -1) { out.write(buf, 0, bytesRead); } in.close(); out.close(); boolean res = tmpFile.renameTo(jarFile); if (!res) { throw new Exception("Could not rename file."); } } catch (Exception e) { e.printStackTrace(); return null; } } if (!jarFile.exists()) { System.out.println("Failed to get JAR file " + jarFile.getName()); return null; } // Launch the new JVM try { List<String> command = new ArrayList<String>(); command.add("java"); command.add("-jar"); command.add(jarFile.getAbsolutePath()); command.add(activityURI.toString()); System.out.println("Executing: " + command.toString()); ProcessBuilder pb = new ProcessBuilder(command); pb.directory(jarFile.getParentFile()); pb.redirectErrorStream(true); Process p = pb.start(); // TODO: make sure it worked return p; } catch (Exception e) { System.out.println("failed to launch JAR."); e.printStackTrace(); } return null; }
From source file:org.o3project.ocnrm.lib.flow.OduFlowCreatorTest.java
/** * Test method for/*from w ww . ja v a 2 s .c om*/ * {@link org.o3project.ocnrm.lib.flow.OduFlowCreator#createFlow()} */ @Test public void testCreateFlowWithEmptyTerminationPoints() throws JsonParseException, JsonMappingException, IOException { point = new TerminationPoints(); String srcJson = "{" + "\"dpid\": \"srcDpid\"," + "\"odutype\": \"srcOdutype\"," + "\"port\": \"srcPort\"," + "\"tpn\": \"-1\"," + "\"ts\": \"srcTs,ts2\"" + "}"; String dstJson = "{" + "\"dpid\": \"dstDpid\"," + "\"odutype\": \"dstOdutype\"," + "\"port\": \"dstPort\"," + "\"tpn\": \"-1\"," + "\"ts\": \"dstTs,ts2\"" + "}"; data = new OduBindingData(); data.bind("src", srcJson); data.bind("dst", dstJson); OptFlow flow = new OptFlow(); flow.setTerminationPointPairs(new ArrayList<TerminationPoints>()); List<String> result = target.createFlow(flow, data, seqNo); assertThat(result.toString(), is("[]")); }
From source file:edu.harvard.i2b2.oauth2.register.ejb.ClientManager.java
public List<Client> list() { List<Client> subList = new ArrayList<Client>(); List<Client> fullList = new ArrayList<Client>(); User authorizedUser = getSessionUser(); logger.debug("Found authenticatedUser: " + authorizedUser); fullList = service.list();/*ww w .j a v a2s. c om*/ for (Client c : fullList) { if (c != null && authorizedUser != null && c.getUser().getId() == authorizedUser.getId()) { subList.add(c); } } logger.debug("fullList:" + fullList + "\nsubList:" + subList.toString()); return subList; }
From source file:com.liferay.sync.engine.service.SyncFileServiceTest.java
@Test public void testUnsyncFolders() throws Exception { List<SyncFile> syncFiles = new ArrayList<>(); SyncFile folderSyncFileA = SyncFileTestUtil.addFolderSyncFile(FileUtil.getFilePathName(filePathName, "a"), syncAccount.getSyncAccountId()); syncFiles.add(folderSyncFileA);/* w w w . ja v a 2 s.com*/ SyncFile folderSyncFileAA = SyncFileTestUtil.addFolderSyncFile( FileUtil.getFilePathName(filePathName, "a", "a"), folderSyncFileA.getTypePK(), syncAccount.getSyncAccountId()); syncFiles.add(folderSyncFileAA); SyncFile folderSyncFileAB = SyncFileTestUtil.addFolderSyncFile( FileUtil.getFilePathName(filePathName, "a", "b"), folderSyncFileA.getTypePK(), syncAccount.getSyncAccountId()); syncFiles.add(folderSyncFileAB); SyncFile folderSyncFileAAA = SyncFileTestUtil.addFolderSyncFile( FileUtil.getFilePathName(filePathName, "a", "a", "a"), folderSyncFileAA.getTypePK(), syncAccount.getSyncAccountId()); syncFiles.add(folderSyncFileAAA); SyncFilePersistence syncFilePersistence = SyncFileService.getSyncFilePersistence(); List<SyncFile> syncedSyncFiles = syncFilePersistence.queryForEq("state", SyncFile.STATE_SYNCED); int previousSyncedSyncFilesSize = syncedSyncFiles.size(); SyncFileService.unsyncFolders(syncAccount.getSyncAccountId(), syncFiles); syncedSyncFiles = syncFilePersistence.queryForEq("state", SyncFile.STATE_SYNCED); Assert.assertEquals(syncedSyncFiles.toString(), previousSyncedSyncFilesSize - 4, syncedSyncFiles.size()); for (SyncFile syncFile : syncFiles) { syncFilePersistence.delete(syncFile); } }
From source file:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter.java
@Override public Map<String, Object> getData(Map<String, Object> pageData) { this.setTemplateName(); HashMap<String, Object> data = new HashMap<String, Object>(); try {/* w w w . j a v a2s . c o m*/ List<String> classes = retrieveClasses(context, classIntersectionsMap); List<String> restrictClasses = retrieveRestrictClasses(context, classIntersectionsMap); log.debug("Retrieving classes for " + classes.toString() + " and restricting by " + restrictClasses.toString()); processClassesAndRestrictions(vreq, context, data, classes, restrictClasses); //Also add data service url //Hardcoding for now, need a more dynamic way of doing this data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl()); //this is the class group associated with the data getter utilized for display on menu editing, not the custom one created data.put("classGroupUri", this.classGroupURI); //default template, overridden at page level if specified in display model data.put("bodyTemplate", defaultTemplate); } catch (Exception ex) { log.error("An error occurred retrieving Vclass Intersection individuals", ex); } return data; }
From source file:com.huateng.commquery.dao.CommQueryDAO.java
public String findCountBySQLQuery(final String sql, boolean needReturnValue) { List data = getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createSQLQuery(sql); return query.list(); }// w w w .j a v a 2 s . c o m }); if (data == null || "".equals(data.toString()) || data.size() == 0) { return "__noDataCanFind"; } return data.get(0).toString(); }
From source file:net.acesinc.data.json.generator.log.TranquilityLogger.java
public TranquilityLogger(Map<String, Object> props) { this.jsonUtils = new JsonUtils(); this.mapper = new ObjectMapper(); this.indexService = (String) props.get(OVERLORD_NAME_PROP_NAME); this.firehosePattern = (String) props.get(FIREHOSE_PATTERN_PROP_NAME); this.discoveryPath = (String) props.get(DISCOVERY_PATH_PROP_NAME); this.dataSourceName = (String) props.get(DATASOURCE_NAME_PROP_NAME); this.dimensionNames = (String) props.get(DIMENSIONS_PROP_NAME); this.geoSpatialDims = (String) props.get(GEOSPATIAL_DIMENSIONS_PROP_NAME); this.timestampName = (String) props.get(TIMESTAMP_NAME_PROP_NAME); this.timestampFormat = (String) props.getOrDefault(TIMESTAMP_FORMAT_PROP_NAME, "auto"); this.segmentGranularity = ((String) props.getOrDefault(SEGMENT_GRANULARITY_PROP_NAME, "hour")) .toUpperCase();//from w ww. j a v a 2s. c o m this.queryGranularity = ((String) props.getOrDefault(QUERY_GRANULARITY_PROP_NAME, "minute")).toUpperCase(); this.zookeeperHost = (String) props.get(ZOOKEEPER_HOST_PROP_NAME); this.zookeeperPort = (Integer) props.get(ZOOKEEPER_PORT_PROP_NAME); this.flatten = (Boolean) props.getOrDefault(FLATTEN_PROP_NAME, true); this.sync = (Boolean) props.getOrDefault(SYNC_PROP_NAME, false); dimensions = new ArrayList<>(); if (dimensionNames != null && !dimensionNames.isEmpty()) { String[] dims = dimensionNames.split(","); for (String s : dims) { dimensions.add(s.trim()); } } if (dimensions.isEmpty()) { log.debug("Configuring Tranquility with Schemaless ingestion"); druidDimensions = DruidDimensions.schemaless(); } else { log.debug("Configuring Tranqulity with the following dimensions: " + dimensions.toString()); druidDimensions = DruidDimensions.specific(dimensions); } List<String> geoDims = new ArrayList<>(); if (geoSpatialDims != null && !geoSpatialDims.isEmpty()) { String[] dims = geoSpatialDims.split(","); for (String s : dims) { geoDims.add(s.trim()); } } if (!geoDims.isEmpty()) { log.debug("Adding Geospatial Dimensions: " + geoDims.toString()); druidDimensions = druidDimensions .withSpatialDimensions(Lists.newArrayList(DruidSpatialDimension.multipleField("geo", geoDims))); } aggregators = ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("events")); // Tranquility needs to be able to extract timestamps from your object type (in this case, Map<String, Object>). timestamper = new Timestamper<Map<String, Object>>() { @Override public DateTime timestamp(Map<String, Object> theMap) { return new DateTime(theMap.get(timestampName)); } }; // Tranquility uses ZooKeeper (through Curator) for coordination. curator = CuratorFrameworkFactory.builder().connectString(zookeeperHost + ":" + zookeeperPort.toString()) .retryPolicy(new ExponentialBackoffRetry(1000, 20, 30000)).build(); curator.start(); // The JSON serialization of your object must have a timestamp field in a format that Druid understands. By default, // Druid expects the field to be called "timestamp" and to be an ISO8601 timestamp. log.debug("Confiuring Tranqulity Timestamp Spec with { name: " + timestampName + ", format: " + timestampFormat + " }"); timestampSpec = new TimestampSpec(timestampName, timestampFormat); // Tranquility needs to be able to serialize your object type to JSON for transmission to Druid. By default this is // done with Jackson. If you want to provide an alternate serializer, you can provide your own via ```.objectWriter(...)```. // In this case, we won't provide one, so we're just using Jackson. log.debug("Creating Druid Beam for DataSource [ " + dataSourceName + " ]"); druidService = DruidBeams.builder(timestamper).curator(curator).discoveryPath(discoveryPath) .location(DruidLocation.create(indexService, firehosePattern, dataSourceName)) .timestampSpec(timestampSpec) .rollup(DruidRollup.create(druidDimensions, aggregators, QueryGranularity.fromString(queryGranularity))) .tuning(ClusteredBeamTuning.builder().segmentGranularity(Granularity.valueOf(segmentGranularity)) .windowPeriod(new Period("PT10M")).partitions(1).replicants(1).build()) .buildJavaService(); }
From source file:com.legstar.cob2xsd.Cob2Xsd.java
/** * Generate an XML Schema using a model of COBOL data items. The model is a * list of root level items. From these, we only process group items * (structures) with children.//from ww w . j a v a 2 s .com * * @param cobolDataItems a list of COBOL data items * @return the XML schema */ public XmlSchema emitXsd(final List<CobolDataItem> cobolDataItems) { if (_log.isDebugEnabled()) { debug("5. Emitting XML Schema from model: ", cobolDataItems.toString()); } XmlSchema xsd = createXmlSchema(getModel().getXsdEncoding()); List<String> nonUniqueCobolNames = getNonUniqueCobolNames(cobolDataItems); XsdEmitter emitter = new XsdEmitter(xsd, getModel()); for (CobolDataItem cobolDataItem : cobolDataItems) { if (getModel().ignoreOrphanPrimitiveElements() && cobolDataItem.getChildren().size() == 0) { continue; } XsdDataItem xsdDataItem = new XsdDataItem(cobolDataItem, getModel(), null, 0, nonUniqueCobolNames, _errorHandler); xsd.getItems().add(emitter.createXmlSchemaElement(xsdDataItem)); } return xsd; }
From source file:gov.nih.nci.cabig.labviewer.grid.LabViewerRegistrationConsumer.java
/** * @param callerId/*from w w w. jav a2 s .c o m*/ * @throws RegistrationConsumptionException */ private void checkAuthorization(String callerId, Registration registration) throws RegistrationConsumptionException { if (callerId == null) { log.error("Error saving participant: no user credentials provided"); throw createRegistrationConsumptionException("No user credentials provided"); } log.debug("Service called by: " + callerId); int beginIndex = callerId.lastIndexOf("=") + 1; int endIndex = callerId.length(); String username = callerId.substring(beginIndex, endIndex); log.debug("Username = " + username); try { Map<SuiteRole, SuiteRoleMembership> userRoleMemberships = getAuthorizationHelper() .getUserRoleMemberships(username); SuiteRole registrationConsumerRole = SuiteRole.REGISTRAR; if (userRoleMemberships.containsKey(registrationConsumerRole)) { log.debug("User role memberships contains role: " + registrationConsumerRole.toString()); if (registrationConsumerRole.isScoped()) { log.debug("Role is scoped: " + registrationConsumerRole.toString()); SuiteRoleMembership userRoleMembership = userRoleMemberships.get(registrationConsumerRole); if (registrationConsumerRole.isStudyScoped()) { log.debug("Role is study scoped: " + registrationConsumerRole.toString()); String studyId = getStudyId(registration); if (studyId == null) { throw new SuiteAuthorizationAccessException( "Role %s is study scoped - study identifier is null", registrationConsumerRole.getDisplayName()); } log.debug("StudyId = " + studyId); // if the user has permission to access specific studies (not all studies), then verify the study if (!userRoleMembership.isAllStudies() && !userRoleMembership.getStudyIdentifiers().contains(studyId)) { throw new SuiteAuthorizationAccessException( "Username %s is not authorized for study %s", username, studyId); } log.debug("User is authorized for study"); } if (registrationConsumerRole.isSiteScoped()) { log.debug("Role is site scoped: " + registrationConsumerRole.toString()); List<String> siteNciInstituteCodes = getSiteNciInstituteCodes(registration); log.debug("Site NCI institute codes = " + siteNciInstituteCodes.toString()); if (siteNciInstituteCodes.isEmpty()) { throw new SuiteAuthorizationAccessException( "Role %s is site scoped - site NCI institute code is null", registrationConsumerRole.getDisplayName()); } // if the user has permission to access specific sites (not all sites), then verify the sites if (!userRoleMembership.isAllSites()) { log.debug("User is NOT authorized for all sites"); boolean userAuthorizedForSite = false; for (String siteNciInstituteCode : siteNciInstituteCodes) { log.debug("Checking site NCI institute code: " + siteNciInstituteCode); if (userRoleMembership.getSiteIdentifiers().contains(siteNciInstituteCode)) { log.debug("User is authorized for site NCI institute code:" + siteNciInstituteCode); userAuthorizedForSite = true; } } log.info("userAuthorizedForSite = " + userAuthorizedForSite); if (!userAuthorizedForSite) { throw new SuiteAuthorizationAccessException( "Username %s is not authorized for sites %s", username, siteNciInstituteCodes.toString()); } } } } } else { throw new SuiteAuthorizationAccessException("Username %s is not authorized for role %s", username, registrationConsumerRole.getDisplayName()); } } catch (SuiteAuthorizationAccessException e) { log.error("Error saving participant: ", e); throw createRegistrationConsumptionException(e.getMessage()); } catch (Exception e) { log.error("Error saving participant: ", e); throw createRegistrationConsumptionException(e.getMessage()); } }