/** * Contacts Hackystat services, gets data, and returns a summary as a string. * * @return The summary of Hackystat activity. */ public String getInfo() { // First, validate that we are authorized for these Hackystat services. SensorBaseClient sensorbaseClient; DailyProjectDataClient dpdClient; try { sensorbaseClient = new SensorBaseClient(sensorbaseHost, user, password); dpdClient = new DailyProjectDataClient(dpdHost, user, password); sensorbaseClient.authenticate(); dpdClient.authenticate(); } catch (Exception e) { return "Error getting Hackystat info. Message is: " + e.getMessage(); } // Second, validate that we can get info about the specified project. try { sensorbaseClient.inProject(projectName, projectOwner); } catch (Exception e) { return String.format("%s is not in project %s", user, projectName); } // We're OK, so figure out the time interval of interest. XMLGregorianCalendar endTime = Tstamp.makeTimestamp(); XMLGregorianCalendar startTime = Tstamp.incrementMinutes(endTime, (-1 * interval)); // Now get information. StringBuffer info = new StringBuffer(); info.append(getDevEventInfo(sensorbaseClient, startTime, endTime)).append(' '); info.append(getCommitInfo(sensorbaseClient, startTime, endTime)).append(' '); info.append(getUnitTestInfo(sensorbaseClient, startTime, endTime)).append(' '); info.append(getBuildInfo(sensorbaseClient, startTime, endTime)).append(' '); info.append(getCoverageInfo(sensorbaseClient, dpdClient, startTime, endTime)).append(' '); info.append(getSizeInfo(sensorbaseClient, dpdClient, startTime, endTime)).append(' '); // Return the info we've found. return info.toString().trim().replace(" ", " "); }
/** * Returns an UnitTestDailyProjectData instance. * * @param variant The representational variant requested. * @return The representation. */ @Override public Representation represent(Variant variant) { Logger logger = this.server.getLogger(); logger.fine("UnitTest DPD: Starting"); if (variant.getMediaType().equals(MediaType.TEXT_XML)) { try { // [1] get the SensorBaseClient for the user making this request. SensorBaseClient client = super.getSensorBaseClient(); // [2] Check the front side cache and return if the DPD is found and is OK to access. String cachedDpd = this.server.getFrontSideCache().get(uriUser, project, uriString); if ((cachedDpd != null) && client.inProject(uriUser, project)) { return super.getStringRepresentation(cachedDpd); } // [2] get a SensorDataIndex of UnitTest sensor data for this Project on the requested day. XMLGregorianCalendar startTime = Tstamp.makeTimestamp(this.timestamp); XMLGregorianCalendar endTime = Tstamp.incrementDays(startTime, 1); logger.fine("UnitTest DPD: Requesting index: " + uriUser + " " + project); SensorDataIndex index = client.getProjectSensorData(uriUser, project, startTime, endTime, "UnitTest"); // [3] Update the counter with this data. logger.fine("UnitTest DPD: Got index. " + index.getSensorDataRef().size() + " instances"); UnitTestCounter counter = new UnitTestCounter(); for (SensorDataRef ref : index.getSensorDataRef()) { counter.add(client.getSensorData(ref)); } logger.fine("UnitTest DPD: Finished retrieving instances. "); // return resulting data UnitTestDailyProjectData unitTestDPD = new UnitTestDailyProjectData(); // create the individual MemberData elements. String sensorBaseHost = this.server.getServerProperties().get(SENSORBASE_FULLHOST_KEY); for (String member : counter.getMembers()) { MemberData memberData = new MemberData(); memberData.setMemberUri(sensorBaseHost + "users/" + member); memberData.setSuccess(counter.getPassCount(member)); memberData.setFailure(counter.getFailCount(member)); unitTestDPD.getMemberData().add(memberData); } unitTestDPD.setOwner(uriUser); unitTestDPD.setProject(project); unitTestDPD.setStartTime(startTime); unitTestDPD.setUriPattern("**"); // we don't support UriPatterns yet. String xmlData = makeUnitTestDPD(unitTestDPD); if (!Tstamp.isTodayOrLater(startTime)) { this.server.getFrontSideCache().put(uriUser, project, uriString, xmlData); } logRequest("UnitTest"); return super.getStringRepresentation(xmlData); } catch (Exception e) { setStatusError("Error creating UnitTest DPD.", e); return null; } } return null; }