private void writeApis(Collection<ApiDeclaration> apis) throws IOException { List<ResourceListingAPI> resources = new LinkedList<ResourceListingAPI>(); File outputDirectory = this.options.getOutputDirectory(); Recorder recorder = this.options.getRecorder(); for (ApiDeclaration api : apis) { String resourcePath = api.getResourcePath(); if (!Strings.isNullOrEmpty(resourcePath)) { // make sure the filename for the resource is valid String resourceFile = ParserHelper.generateResourceFilename(resourcePath); resources.add( new ResourceListingAPI("/" + resourceFile + ".{format}", api.getDescription())); File apiFile = new File(outputDirectory, resourceFile + ".json"); recorder.record(apiFile, api); } } // write out json for the resource listing ResourceListing listing = new ResourceListing( SWAGGER_VERSION, this.options.getApiVersion(), this.options.getDocBasePath(), resources, this.options.getApiAuthorizations(), this.options.getApiInfo()); File docFile = new File(outputDirectory, "service.json"); recorder.record(docFile, listing); }
public void setScoringDefinition(Scoring scoring) { for (ScoringElement element : scoring.getElements()) { ParserHelper.resolveConditionType(definitionsService, element.getCondition()); } for (ScoringElement element : scoring.getElements()) { if (scoring.getMetadata().isEnabled() && !scoring.getMetadata().isMissingPlugins()) { updateAutoGeneratedRules(scoring.getMetadata(), element.getCondition()); } } // make sure we update the name and description metadata that might not match, so first we // remove the entry from the map persistenceService.save(scoring); persistenceService.createMapping( Profile.ITEM_TYPE, String.format( "{\n" + " \"profile\": {\n" + " \"properties\" : {\n" + " \"scores\": {\n" + " \"properties\": {\n" + " \"%s\": {\n" + " \"type\": \"long\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}\n", scoring.getItemId())); updateExistingProfilesForScoring(scoring); }
public Segment getSegmentDefinition(String segmentId) { Segment definition = persistenceService.load(segmentId, Segment.class); if (definition != null) { ParserHelper.resolveConditionType(definitionsService, definition.getCondition()); } return definition; }
/** * Compile the query (generate the SQL). * * @throws org.hibernate.MappingException Indicates problems resolving things referenced in the * query. * @throws org.hibernate.QueryException Generally some form of syntatic failure. */ private void compile() throws QueryException, MappingException { LOG.trace("Compiling query"); try { ParserHelper.parse( new PreprocessingParser(tokenReplacements), queryString, ParserHelper.HQL_SEPARATORS, this); renderSQL(); } catch (QueryException qe) { qe.setQueryString(queryString); throw qe; } catch (MappingException me) { throw me; } catch (Exception e) { LOG.debug("Unexpected query compilation problem", e); e.printStackTrace(); QueryException qe = new QueryException("Incorrect query syntax", e); qe.setQueryString(queryString); throw qe; } postInstantiate(); compiled = true; }
private List<Segment> getAllSegmentDefinitions() { List<Segment> allItems = persistenceService.getAllItems(Segment.class); for (Segment segment : allItems) { ParserHelper.resolveConditionType(definitionsService, segment.getCondition()); } return allItems; }
public Scoring getScoringDefinition(String scoringId) { Scoring definition = persistenceService.load(scoringId, Scoring.class); if (definition != null) { for (ScoringElement element : definition.getElements()) { ParserHelper.resolveConditionType(definitionsService, element.getCondition()); } } return definition; }
private List<Scoring> getAllScoringDefinitions() { List<Scoring> allItems = persistenceService.getAllItems(Scoring.class); for (Scoring scoring : allItems) { for (ScoringElement element : scoring.getElements()) { ParserHelper.resolveConditionType(definitionsService, element.getCondition()); } } return allItems; }
public void setSegmentDefinition(Segment segment) { ParserHelper.resolveConditionType(definitionsService, segment.getCondition()); if (segment.getMetadata().isEnabled() && !segment.getMetadata().isMissingPlugins()) { updateAutoGeneratedRules(segment.getMetadata(), segment.getCondition()); } // make sure we update the name and description metadata that might not match, so first we // remove the entry from the map persistenceService.save(segment); updateExistingProfilesForSegment(segment); }
public boolean run() { try { // setup additional classes needed for processing, generally these are java ones such as // java.lang.String // adding them here allows them to be used in @outputType Collection<ClassDoc> typeClasses = new ArrayList<ClassDoc>(); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.String.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Integer.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Boolean.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Float.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Double.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Character.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Long.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.lang.Byte.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.Date.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.Calendar.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.Map.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.Collection.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.Set.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.List.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.math.BigInteger.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.math.BigDecimal.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.util.UUID.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.DayOfWeek.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.Duration.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.Instant.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.LocalDate.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.LocalDateTime.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.Month.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.MonthDay.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.OffsetDateTime.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.OffsetTime.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.Period.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.Year.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.YearMonth.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.ZoneId.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.ZoneOffset.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.time.ZonedDateTime.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.net.URI.class.getName())); addIfNotNull(typeClasses, this.rootDoc.classNamed(java.net.URL.class.getName())); // filter the classes to process Collection<ClassDoc> docletClasses = new ArrayList<ClassDoc>(); for (ClassDoc classDoc : this.rootDoc.classes()) { // see if excluded via its FQN boolean excludeResource = false; if (this.options.getExcludeResourcePrefixes() != null && !this.options.getExcludeResourcePrefixes().isEmpty()) { for (String prefix : this.options.getExcludeResourcePrefixes()) { String className = classDoc.qualifiedName(); if (className.startsWith(prefix)) { excludeResource = true; break; } } } // see if the inclusion filter is set and if so this resource must match this if (!excludeResource && this.options.getIncludeResourcePrefixes() != null && !this.options.getIncludeResourcePrefixes().isEmpty()) { boolean matched = false; for (String prefix : this.options.getIncludeResourcePrefixes()) { String className = classDoc.qualifiedName(); if (className.startsWith(prefix)) { matched = true; break; } } excludeResource = !matched; } if (excludeResource) { continue; } // see if deprecated if (this.options.isExcludeDeprecatedResourceClasses() && ParserHelper.isDeprecated(classDoc, this.options)) { continue; } // see if excluded via a tag if (ParserHelper.hasTag(classDoc, this.options.getExcludeClassTags())) { continue; } docletClasses.add(classDoc); } ClassDocCache classCache = new ClassDocCache(docletClasses); List<ApiDeclaration> declarations = null; // build up set of subresources // do simple parsing to find sub resource classes // these are ones referenced in the return types of methods // which have a path but no http method Map<Type, ClassDoc> subResourceClasses = new HashMap<Type, ClassDoc>(); for (ClassDoc classDoc : docletClasses) { ClassDoc currentClassDoc = classDoc; while (currentClassDoc != null) { for (MethodDoc method : currentClassDoc.methods()) { // if the method has @Path but no Http method then its an entry point to a sub resource if (!ParserHelper.resolveMethodPath(method, this.options).isEmpty() && HttpMethod.fromMethod(method) == null) { ClassDoc subResourceClassDoc = classCache.findByType(method.returnType()); if (subResourceClassDoc != null) { if (this.options.isLogDebug()) { System.out.println( "Adding return type as sub resource class : " + subResourceClassDoc.name() + " for method " + method.name() + " of referencing class " + currentClassDoc.name()); } subResourceClasses.put(method.returnType(), subResourceClassDoc); } } } currentClassDoc = currentClassDoc.superclass(); // ignore parent object class if (!ParserHelper.hasAncestor(currentClassDoc)) { break; } } } // parse with the v2 parser that supports endpoints of the same resource being spread across // resource files Map<String, ApiDeclaration> resourceToDeclaration = new HashMap<String, ApiDeclaration>(); for (ClassDoc classDoc : docletClasses) { CrossClassApiParser classParser = new CrossClassApiParser( this.options, classDoc, docletClasses, subResourceClasses, typeClasses, SWAGGER_VERSION, this.options.getApiVersion(), this.options.getApiBasePath()); classParser.parse(resourceToDeclaration); } Collection<ApiDeclaration> declarationColl = resourceToDeclaration.values(); if (this.options.isLogDebug()) { System.out.println("After parse phase api declarations are: "); for (ApiDeclaration apiDec : declarationColl) { System.out.println( "Api Dec: base path " + apiDec.getBasePath() + ", res path: " + apiDec.getResourcePath()); for (Api api : apiDec.getApis()) { System.out.println("Api path:" + api.getPath()); for (Operation op : api.getOperations()) { System.out.println("Api nick name:" + op.getNickname() + " method " + op.getMethod()); } } } } // add any extra declarations if (this.options.getExtraApiDeclarations() != null && !this.options.getExtraApiDeclarations().isEmpty()) { declarationColl = new ArrayList<ApiDeclaration>(declarationColl); declarationColl.addAll(this.options.getExtraApiDeclarations()); } // set root path on any empty resources for (ApiDeclaration api : declarationColl) { if (api.getResourcePath() == null || api.getResourcePath().isEmpty() || api.getResourcePath().equals("/")) { api.setResourcePath(this.options.getResourceRootPath()); } } // merge the api declarations declarationColl = new ApiDeclarationMerger( SWAGGER_VERSION, this.options.getApiVersion(), this.options.getApiBasePath()) .merge(declarationColl); // clear any empty models for (ApiDeclaration api : declarationColl) { if (api.getModels() != null && api.getModels().isEmpty()) { api.setModels(null); } } declarations = new ArrayList<ApiDeclaration>(declarationColl); // sort the api declarations if needed if (this.options.isSortResourcesByPriority()) { Collections.sort( declarations, new Comparator<ApiDeclaration>() { public int compare(ApiDeclaration dec1, ApiDeclaration dec2) { return Integer.compare(dec1.getPriority(), dec2.getPriority()); } }); } else if (this.options.isSortResourcesByPath()) { Collections.sort( declarations, new Comparator<ApiDeclaration>() { public int compare(ApiDeclaration dec1, ApiDeclaration dec2) { if (dec1 == null || dec1.getResourcePath() == null) { return 1; } if (dec2 == null || dec2.getResourcePath() == null) { return -1; } return dec1.getResourcePath().compareTo(dec2.getResourcePath()); } }); } // sort apis of each declaration if (this.options.isSortApisByPath()) { for (ApiDeclaration dec : declarations) { if (dec.getApis() != null) { Collections.sort( dec.getApis(), new Comparator<Api>() { public int compare(Api o1, Api o2) { if (o1 == null || o1.getPath() == null) { return -1; } return o1.getPath().compareTo(o2.getPath()); } }); } } } writeApis(declarations); // Copy swagger-ui into the output directory. if (this.options.isIncludeSwaggerUi()) { copyUi(); } return true; } catch (IOException e) { System.err.println("Failed to write api docs, err msg: " + e.getMessage()); e.printStackTrace(); return false; } }
public void reportError(Exception ex) { if (state.backtracking == 0) { helper.reportError(ex); } }
public LinkedList<DroolsSentence> getEditorInterface() { return helper.getEditorInterface(); }
public void disableEditorInterface() { helper.disableEditorInterface(); }
public void enableEditorInterface() { helper.enableEditorInterface(); }
public List<DroolsParserException> getErrors() { return helper.getErrors(); }
public boolean hasErrors() { return helper.hasErrors(); }
/** * This is where the hard-to-parse paths are handled. Uppercase rules are absolute positions, * lowercase are relative. Types of path rules: * * <p> * * <ol> * <li>M/m - (x y)+ - Move to (without drawing) * <li>Z/z - (no params) - Close path (back to starting point) * <li>L/l - (x y)+ - Line to * <li>H/h - x+ - Horizontal ine to * <li>V/v - y+ - Vertical line to * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from * previous C/S is the x1, y1 of this bezier) * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" * of last one w.r.t. to current point) * </ol> * * <p>Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, * (ie. begin with a - sign) * * @param s the path string from the XML */ private static Path doPath(String s) { int n = s.length(); ParserHelper ph = new ParserHelper(s, 0); ph.skipWhitespace(); Path p = new Path(); float lastX = 0; float lastY = 0; float lastX1 = 0; float lastY1 = 0; float subPathStartX = 0; float subPathStartY = 0; char prevCmd = 0; while (ph.pos < n) { char cmd = s.charAt(ph.pos); switch (cmd) { case '-': case '+': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (prevCmd == 'm' || prevCmd == 'M') { cmd = (char) (((int) prevCmd) - 1); break; } else if (prevCmd == 'c' || prevCmd == 'C') { cmd = prevCmd; break; } else if (prevCmd == 'l' || prevCmd == 'L') { cmd = prevCmd; break; } default: { ph.advance(); prevCmd = cmd; } } boolean wasCurve = false; switch (cmd) { case 'M': case 'm': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'm') { subPathStartX += x; subPathStartY += y; p.rMoveTo(x, y); lastX += x; lastY += y; } else { subPathStartX = x; subPathStartY = y; p.moveTo(x, y); lastX = x; lastY = y; } break; } case 'Z': case 'z': { p.close(); p.moveTo(subPathStartX, subPathStartY); lastX = subPathStartX; lastY = subPathStartY; lastX1 = subPathStartX; lastY1 = subPathStartY; wasCurve = true; break; } case 'L': case 'l': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'l') { p.rLineTo(x, y); lastX += x; lastY += y; } else { p.lineTo(x, y); lastX = x; lastY = y; } break; } case 'H': case 'h': { float x = ph.nextFloat(); if (cmd == 'h') { p.rLineTo(x, 0); lastX += x; } else { p.lineTo(x, lastY); lastX = x; } break; } case 'V': case 'v': { float y = ph.nextFloat(); if (cmd == 'v') { p.rLineTo(0, y); lastY += y; } else { p.lineTo(lastX, y); lastY = y; } break; } case 'C': case 'c': { wasCurve = true; float x1 = ph.nextFloat(); float y1 = ph.nextFloat(); float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'c') { x1 += lastX; x2 += lastX; x += lastX; y1 += lastY; y2 += lastY; y += lastY; } p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'S': case 's': { wasCurve = true; float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 's') { x2 += lastX; x += lastX; y2 += lastY; y += lastY; } float x1 = 2 * lastX - lastX1; float y1 = 2 * lastY - lastY1; p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'A': case 'a': { float rx = ph.nextFloat(); float ry = ph.nextFloat(); float theta = ph.nextFloat(); int largeArc = (int) ph.nextFloat(); int sweepArc = (int) ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc); lastX = x; lastY = y; break; } } if (!wasCurve) { lastX1 = lastX; lastY1 = lastY; } ph.skipWhitespace(); } return p; }
public List<String> getErrorMessages() { return helper.getErrorMessages(); }