private String getCIJobPath(ApplicationInfo appInfo) { StringBuilder builder = new StringBuilder(Utility.getProjectHome()); builder.append(appInfo.getAppDirName()); builder.append(File.separator); builder.append(FOLDER_DOT_PHRESCO); builder.append(File.separator); builder.append(CI_JOB_INFO_NAME); return builder.toString(); }
@PUT @Path("/testcases") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateTestCase( com.photon.phresco.commons.model.TestCase testCase, @QueryParam("testSuiteName") String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); frameworkUtil.readManualTestCaseFile(sb.toString(), testSuiteName, testCase); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400006); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410008); return Response.status(Status.OK).entity(finalOutput).build(); } }
@POST @Path(REST_API_TESTSUITES) @Produces(MediaType.APPLICATION_JSON) public Response createTestSuite( @QueryParam(REST_API_TESTSUITE) String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); String cellValue[] = {"", "", testSuiteName, "", "", "", "", "", "", "", "", "", ""}; frameworkUtil.addNew(sb.toString(), testSuiteName, cellValue); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400004); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { e.printStackTrace(); ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410006); return Response.status(Status.OK).entity(finalOutput).build(); } }
@Override public void postFeatureConfiguration( ApplicationInfo appInfo, List<Configuration> configs, String featureName) throws PhrescoException { try { String propertyValue = getPropertyValue(appInfo, Constants.POM_PROP_KEY_SQL_FILE_DIR); File featureManifest = new File( Utility.getProjectHome() + appInfo.getAppDirName() + getThirdPartyFolder(appInfo) + File.separator + featureName + File.separator + XML); File featureSqlDir = new File(Utility.getProjectHome() + appInfo.getAppDirName() + propertyValue); if (CollectionUtils.isNotEmpty(configs)) { String envName = configs.get(0).getEnvName(); storeConfigObj(configs, featureManifest, featureSqlDir, envName); } } catch (Exception e) { throw new PhrescoException(e); } }
@Override public PossibleValues getValues(Map<String, Object> map) throws IOException, ParserConfigurationException, SAXException, ConfigurationException, PhrescoException { String rootModulePath = ""; String subModuleName = ""; PossibleValues possibleValues = new PossibleValues(); ApplicationInfo applicationInfo = (ApplicationInfo) map.get(KEY_APP_INFO); String rootModule = (String) map.get(KEY_ROOT_MODULE); if (StringUtils.isNotEmpty(rootModule)) { rootModulePath = Utility.getProjectHome() + rootModule; subModuleName = applicationInfo.getAppDirName(); } else { rootModulePath = Utility.getProjectHome() + applicationInfo.getAppDirName(); } String buildInfoPath = getBuildInfoPath(rootModulePath, subModuleName).toString(); List<BuildInfo> buildInfos = Utility.getBuildInfos(new File(buildInfoPath)); if (buildInfos != null) { for (BuildInfo buildInfo : buildInfos) { Value value = new Value(); value.setValue(Integer.toString(buildInfo.getBuildNo())); String dependency = getDependency(buildInfo.getBuildNo(), rootModulePath, subModuleName); if (!StringUtils.isEmpty(dependency)) { value.setDependency(dependency); } possibleValues.getValue().add(value); } } return possibleValues; }
@DELETE @Path(REST_API_TESTSUITES_DELETE) @Produces(MediaType.APPLICATION_JSON) public Response deleteTestSuites( @QueryParam(REST_API_TESTSUITE) String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo<String> responseData = new ResponseInfo<String>(); ManualTestResult createManualTestResult = null; ResponseInfo<Boolean> finalOutput = null; try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); File manualFilePath = new File(sb.toString()); if (!manualFilePath.exists()) { finalOutput = responseDataEvaluation( responseData, null, createManualTestResult, RESPONSE_STATUS_FAILURE, PHRQ000003); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } boolean deleteManualTestSuiteFile = frameworkUtil.deleteManualTestSuiteFile(sb.toString(), testSuiteName); finalOutput = responseDataEvaluation( responseData, null, deleteManualTestSuiteFile, RESPONSE_STATUS_SUCCESS, PHRQ400008); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } catch (Exception e) { finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410004); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } }
@POST @Path(REST_API_TESTCASES) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response createTestCase( com.photon.phresco.commons.model.TestCase testCase, @QueryParam("testSuiteName") String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); String cellValue[] = { "", testCase.getFeatureId(), "", testCase.getTestCaseId(), testCase.getDescription(), testCase.getPreconditions(), testCase.getSteps(), "", "", testCase.getExpectedResult(), testCase.getActualResult(), testCase.getStatus(), testCase.getBugComment() }; frameworkUtil.addNewTestCase(sb.toString(), testSuiteName, cellValue, testCase.getStatus()); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400005); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { e.printStackTrace(); ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410007); return Response.status(Status.OK).entity(finalOutput).build(); } }
@GET @Path(REST_API_TESTCASE_VALIDATION) @Produces(MediaType.APPLICATION_JSON) public Response testCaseValidation( @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_TESTCASE_NAME) String testCaseId, @QueryParam("testSuiteName") String testsuitename, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo<String> responseData = new ResponseInfo<String>(); List<com.photon.phresco.commons.model.TestCase> readTestCase = null; boolean hasError = true; try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); readTestCase = frameworkUtil.readManualTestCaseFile(sb.toString(), testsuitename, null); for (com.photon.phresco.commons.model.TestCase testCase : readTestCase) { if (testCase.getTestCaseId().equalsIgnoreCase(testCaseId)) { hasError = false; break; } } ResponseInfo<Boolean> finalOutput = responseDataEvaluation(responseData, null, hasError, RESPONSE_STATUS_SUCCESS, PHRQ400007); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } catch (Exception e) { ResponseInfo<Boolean> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410009); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } }
@Override public void postUpdate( ApplicationInfo appInfo, List<ArtifactGroup> artifactGroups, List<ArtifactGroup> deletedFeatures) throws PhrescoException { File pomFile = new File( Utility.getProjectHome() + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); ProjectUtils projectUtils = new ProjectUtils(); projectUtils.deletePluginExecutionFromPom(pomFile); if (CollectionUtils.isNotEmpty(deletedFeatures)) { projectUtils.removeExtractedFeatures(appInfo, deletedFeatures); } if (CollectionUtils.isNotEmpty(artifactGroups)) { projectUtils.updatePOMWithPluginArtifact(pomFile, artifactGroups); excludeModule(appInfo, artifactGroups); } BufferedReader breader = projectUtils.ExtractFeature(appInfo); try { String line = ""; while ((line = breader.readLine()) != null) { if (line.startsWith("[ERROR]")) { System.err.println(line); } } } catch (IOException e) { throw new PhrescoException(e); } }
public List<String> validateProjectCode() { DirectoryWalker walker = new DirectoryWalker(); walker.setBaseDir(new File(Utility.getProjectHome())); walker.addDirectoryWalkListener(this); walker.scan(); return invalidProjects; }
@POST @Path(REST_API_UPLOADTEMPLATE) @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response uploadManualTemplate( @Context HttpServletRequest request, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName) throws PhrescoException { ResponseInfo response = new ResponseInfo(); try { String uploadedFileName = request.getHeader(FrameworkConstants.X_FILE_NAME); String fileName = URLDecoder.decode(uploadedFileName, "UTF-8"); InputStream inputStream = request.getInputStream(); String moduleName = request.getHeader("moduleName"); String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } String manualTestPath = getManualTestReportDir(rootModulePath, subModuleName); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); StringBuilder builder = new StringBuilder(manualDir.toString()); builder.append(manualTestPath); File existingFile = new File(builder.toString()); FileUtils.cleanDirectory(existingFile); File file = new File(builder.toString() + File.separator + fileName); FileUtils.copyInputStreamToFile(inputStream, file); } catch (Exception e) { ResponseInfo finalOutput = responseDataEvaluation(response, e, null, RESPONSE_STATUS_ERROR, PHRQ410002); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } ResponseInfo responseData = responseDataEvaluation(response, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400001); return Response.status(Status.OK) .header("Access-Control-Allow-Origin", "*") .entity(responseData) .build(); }
@Override public void postConfiguration(ApplicationInfo appInfo, List<Configuration> configurations) throws PhrescoException { String envName = configurations.get(0).getEnvName(); String featureName = configurations.get(0).getProperties().getProperty(Constants.FEATURE_NAME); String propertyValue = getPropertyValue(appInfo, Constants.POM_PROP_KEY_SQL_FILE_DIR); File featureManifest = new File( Utility.getProjectHome() + appInfo.getAppDirName() + getThirdPartyFolder(appInfo) + File.separator + featureName + File.separator + XML); File featureSqlDir = new File(Utility.getProjectHome() + appInfo.getAppDirName() + propertyValue); if (StringUtils.isNotEmpty(featureName)) { storeConfigObj(configurations, featureManifest, featureSqlDir, envName); } }
@Override public List<Configuration> preConfiguration( ApplicationInfo appInfo, String featureName, String envName) throws PhrescoException { File featureManifest = new File( Utility.getProjectHome() + appInfo.getAppDirName() + getThirdPartyFolder(appInfo) + File.separator + featureName + File.separator + XML); List<Configuration> configs = getConfigObjFromXml(featureManifest.getPath()); return configs; }
private void excludeModule(ApplicationInfo appInfo, List<ArtifactGroup> artifactGroups) throws PhrescoException { try { File projectPath = new File( Utility.getProjectHome() + File.separator + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); PomProcessor processor = new PomProcessor(projectPath); StringBuilder exclusionStringBuff = new StringBuilder(); StringBuilder exclusionValueBuff = new StringBuilder(); if (CollectionUtils.isEmpty(artifactGroups)) { return; } for (ArtifactGroup artifactGroup : artifactGroups) { List<CoreOption> appliesTo = artifactGroup.getAppliesTo(); for (CoreOption coreOption : appliesTo) { if (coreOption.isCore()) { exclusionValueBuff.append(artifactGroup.getName().toLowerCase()); exclusionValueBuff.append(","); exclusionStringBuff.append("**\\"); exclusionStringBuff.append(artifactGroup.getName().toLowerCase()); exclusionStringBuff.append("\\**"); exclusionStringBuff.append(","); } } } String exclusionValue = exclusionStringBuff.toString(); if (exclusionValue.lastIndexOf(',') != -1) { exclusionValue = exclusionValue.substring(0, exclusionValue.lastIndexOf(',')); } String exclusiontoolValue = exclusionValueBuff.toString(); if (exclusiontoolValue.lastIndexOf(',') != -1) { exclusiontoolValue = exclusiontoolValue.substring(0, exclusiontoolValue.lastIndexOf(',')); } processor.setProperty("sonar.exclusions", exclusionValue); processor.setProperty("sonar.phpDepend.argumentLine", "--ignore=" + exclusiontoolValue); processor.setProperty("sonar.phpPmd.argumentLine", "--exclude" + exclusiontoolValue); processor.save(); } catch (PhrescoPomException e) { throw new PhrescoException(e); } }
public String checkForSiteReport() { S_LOGGER.debug("Entering Method SiteReport.checkForSiteReport()"); try { Properties sysProps = System.getProperties(); S_LOGGER.debug( "Phresco FileServer Value of " + PHRESCO_FILE_SERVER_PORT_NO + " is " + sysProps.getProperty(PHRESCO_FILE_SERVER_PORT_NO)); String phrescoFileServerNumber = sysProps.getProperty(PHRESCO_FILE_SERVER_PORT_NO); StringBuilder sb = new StringBuilder(); StringBuilder siteReportPath = new StringBuilder(Utility.getProjectHome()); siteReportPath.append(projectCode); siteReportPath.append(File.separatorChar); siteReportPath.append(SITE_TARGET); siteReportPath.append(File.separatorChar); siteReportPath.append(INDEX_HTML); File indexPath = new File(siteReportPath.toString()); if (indexPath.isFile() && StringUtils.isNotEmpty(phrescoFileServerNumber)) { sb.append(HTTP_PROTOCOL); sb.append(PROTOCOL_POSTFIX); sb.append(LOCALHOST); sb.append(COLON); sb.append(phrescoFileServerNumber); sb.append(FORWARD_SLASH); sb.append(projectCode); sb.append(FORWARD_SLASH); sb.append(SITE_TARGET); sb.append(FORWARD_SLASH); sb.append(INDEX_HTML); getHttpRequest().setAttribute(REQ_SITE_REPORT_PATH, sb.toString()); } else { getHttpRequest().setAttribute(REQ_ERROR, false); } } catch (Exception e) { S_LOGGER.error( "Entered into catch block of SiteReport.checkForSiteReport()" + FrameworkUtil.getStackTraceAsString(e)); new LogErrorReport(e, "Getting site report"); } return APP_SITE_REPORT_VIEW; }
private String getThirdPartyFolder(ApplicationInfo appInfo) throws PhrescoException { File pomPath = new File( Utility.getProjectHome() + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); try { PomProcessor processor = new PomProcessor(pomPath); String property = processor.getProperty(Constants.POM_PROP_KEY_MODULE_SOURCE_DIR); if (StringUtils.isNotEmpty(property)) { return property; } } catch (PhrescoPomException e) { throw new PhrescoException(e); } return ""; }
private String getPropertyValue(ApplicationInfo appInfo, String propertyKey) throws PhrescoException { File pomPath = new File( Utility.getProjectHome() + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); try { PomProcessor processor = new PomProcessor(pomPath); String property = processor.getProperty(propertyKey); if (StringUtils.isNotEmpty(property)) { return property; } } catch (PhrescoPomException e) { throw new PhrescoException(e); } return ""; }
@Override public void postCreate(ApplicationInfo appInfo) throws PhrescoException { File path = new File(Utility.getProjectHome() + appInfo.getAppDirName()); updateDrupalVersion(path, appInfo); }