Related
I have a json schema from which I need to generate java classes
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schema.softsense.io/analysis/vulnerabilities/v1alpha1/vulnerabilities.json",
"title": "Vulnerabilities",
"description": "SoftSense Vulnerabilities analysis schema v1alpha3",
"type": "object",
"allOf": [ { "$ref": "https://schema.softsense.io/analysis/v1alpha3/base.json" } ],
"properties": {
"vulnerabilities": {
"items": {
"$ref": "#/definitions/Vulnerability"
},
"type": "array"
}
},
"oneOf": [{ "required": ["vulnerabilities"] }, { "required": ["error"] }],
"definitions": {
"Vulnerability": {
"required": [
"id",
"description",
"sources"
],
"properties": {
"id": {
"description": "Identifier for the vulnerability, such as a CVE identifier (CVE-2021-12345).",
"type": "string"
},
"published": {
"description": "UTC time when the vulnerability was published",
"type": "string",
"format": "date-time"
},
"updated": {
"description": "UTC time when the vulnerability was updated",
"type": "string",
"format": "date-time"
},
"description": {
"description": "Description of the vulnerability",
"type": "string"
},
"sources": {
"description": "The collection of backing vulnerability sources that listed this vulnerability for the software component",
"items": {
"type": "string"
},
"type": "array"
},
"cwes": {
"description": "The collection of Common Weakness Enumeration (CWE) identifiers that characterize the vulnerability.",
"items": {
"$ref": "#/definitions/CWE"
},
"type": "array"
},
"references": {
"description": "External URLs related to the vulnerability, such as issue trackers, mailing list discussions, commits, or patches.",
"items": {
"$ref": "#/definitions/Reference"
},
"type": "array"
},
"impact": {
"description": "What impact this vulnerability has",
"$ref": "#/definitions/Impact"
}
},
"type": "object"
},
"Impact": {
"properties": {
"metricV3": {
"$ref": "#/definitions/ImpactMetricV3"
},
"metricV2": {
"$ref": "#/definitions/ImpactMetricV2"
},
"*": {
"type": "object"
}
},
"type": "object"
},
"ImpactMetricV3": {
"properties": {
"cvssV3": {
"$ref": "#/definitions/CVSSv3"
},
"exploitabilityScore": {
"type": "number"
},
"impactScore": {
"type": "number"
}
}
},
"CVSSv3": {
"required": [
"version",
"vectorString",
"baseScore",
"baseSeverity"
],
"properties": {
"version": {
"type": "string"
},
"vectorString": {
"type": "string"
},
"attackVector": {
"type": "string"
},
"attackComplexity": {
"type": "string"
},
"privilegesRequired": {
"type": "string"
},
"userInteraction": {
"type": "string"
},
"scope": {
"type": "string"
},
"confidentialityImpact": {
"type": "string"
},
"integrityImpact": {
"type": "string"
},
"availabilityImpact": {
"type": "string"
},
"baseScore": {
"type": "number"
},
"baseSeverity": {
"type": "string"
},
"exploitCodeMaturity": {
"type": "string"
},
"remediationLevel": {
"type": "string"
},
"reportConfidence": {
"type": "string"
},
"temporalScore": {
"type": "number"
},
"temporalSeverity": {
"type": "string"
},
"confidentialityRequirement": {
"type": "string"
},
"integrityRequirement": {
"type": "string"
},
"availabilityRequirement": {
"type": "string"
},
"modifiedAttackVector": {
"type": "string"
},
"modifiedAttackComplexity": {
"type": "string"
},
"modifiedPrivilegesRequired": {
"type": "string"
},
"modifiedUserInteraction": {
"type": "string"
},
"modifiedScope": {
"type": "string"
},
"modifiedConfidentialityImpact": {
"type": "string"
},
"modifiedIntegrityImpact": {
"type": "string"
},
"modifiedAvailabilityImpact": {
"type": "string"
},
"environmentalScore": {
"type": "number"
},
"environmentalSeverity": {
"type": "string"
}
},
"type": "object"
},
"ImpactMetricV2": {
"required": [
"cvssV2",
"severity",
"exploitabilityScore",
"impactScore",
"obtainAllPrivilege",
"obtainUserPrivilege",
"obtainOtherPrivilege",
"userInteractionRequired"
],
"properties": {
"cvssV2": {
"$ref": "#/definitions/CVSSv2"
},
"severity": {
"type": "string"
},
"exploitabilityScore": {
"type": "number"
},
"impactScore": {
"type": "number"
},
"acInsufInfo": {
"type": "boolean"
},
"obtainAllPrivilege": {
"type": "boolean"
},
"obtainUserPrivilege": {
"type": "boolean"
},
"obtainOtherPrivilege": {
"type": "boolean"
},
"userInteractionRequired": {
"type": "boolean"
}
},
"type": "object"
},
"CVSSv2": {
"required": [
"version",
"vectorString",
"baseScore"
],
"properties": {
"version": {
"type": "string"
},
"vectorString": {
"type": "string"
},
"accessVector": {
"type": "string"
},
"accessComplexity": {
"type": "string"
},
"authentication": {
"type": "string"
},
"confidentialityImpact": {
"type": "string"
},
"integrityImpact": {
"type": "string"
},
"availabilityImpact": {
"type": "string"
},
"baseScore": {
"type": "number"
},
"exploitability": {
"type": "string"
},
"remediationLevel": {
"type": "string"
},
"reportConfidence": {
"type": "string"
},
"temporalScore": {
"type": "number"
},
"collateralDamagePotential": {
"type": "string"
},
"targetDistribution": {
"type": "string"
},
"confidentialityRequirement": {
"type": "string"
},
"integrityRequirement": {
"type": "string"
},
"availabilityRequirement": {
"type": "string"
},
"environmentalScore": {
"type": "number"
}
},
"type": "object"
},
"CWE": {
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"type": "object"
},
"Reference": {
"required": [
"url"
],
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
}
}
}
I am trying to use the jsonschema2pojo as under.
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.34</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>com.test.gen</targetPackage>
<useCommonsLang3>true</useCommonsLang3>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
For some reason I get the following error when i use mvn generate-sources
[ERROR] Failed to execute goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate (default) on project hsk: Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate failed: String index out of range: 0 -> [Help 1]
Any help is highly appreciated
Regards,
I am using the Maven Avro plugin to generate POJOs from an AVSC file. Unfortunately, the top-most class that is generated from this file - loanInitiate - does not appear to contain any of the getters and setters needed for the other structures within the schema.
The POJOs that are generated for the child nodes do have the expected getters and setters. For example, the Customer class is generated and has a getNameBase() method.
I have tried editing this file in a variety of ways - changing structure, etc. - but I keep running into situations where the format is not valid.
Why would some of the getters and setters be generated and not others?
The Avro schema file is defined as follows:
{
"fields": [
{
"name": "loanInitiate",
"type": [
{
"type": "record",
"name": "eventheader",
"fields": [
{
"name": "eventType",
"type": "string",
"doc": "Loan"
},
{
"name": "eventSubtype",
"type": "string",
"doc": "Initiate"
},
{
"name": "eventDateTime",
"type": "string"
},
{
"name": "eventGeneratedDateTime",
"type": "string"
},
{
"name": "eventCorrelationId",
"type": [
"string",
"null"
]
},
{
"name": "eventRequestId",
"type": [
"string",
"null"
]
},
{
"name": "eventSourceDescription",
"type": [
"string",
"null"
]
},
{
"name": "eventSource",
"type": [
"string",
"null"
],
"doc": "The producer of this message."
},
{
"name": "eventInitiator",
"type": [
"string",
"null"
]
},
{
"name": "eventBatchGroupId",
"type": [
"string",
"null"
],
"doc": "BatchGroupID represents the GUID value given to each individual message which is part of a single batch."
},
{
"name": "eventBatchRecordCountTotal",
"type": [
"string",
"null"
],
"doc": "BatchRecordCountTotal provides the total number of messages belonging to a single batch."
}
]
},
{
"type": "array",
"name": "customer",
"items": {
"name": "customer",
"type": "record",
"fields": [
{
"name": "nameBase",
"type": {
"type": "record",
"name": "nameBase",
"fields": [
{
"name": "givenName",
"type": "string"
},
{
"name": "otherGivenName",
"type": [
"string",
"null"
]
},
{
"name": "fullName",
"type": "string"
},
{
"name": "suffix",
"type": [
"string",
"null"
]
},
{
"name": "surname",
"type": "string"
},
{
"name": "titlePrefix",
"type": [
"string",
"null"
]
}
]
}
},
{
"name": "party",
"type": {
"type": "record",
"name": "party",
"fields": [
{
"name": "parentEntityId",
"type": "string",
"doc": "The value of this field should equal the value the id field of the parent object."
},
{
"name": "partyRole",
"type": {
"type": "record",
"name": "partyRole",
"fields": [
{
"name": "code",
"type": {
"name": "code",
"type": "enum",
"symbols": [
"INSD",
"OWNR",
"PPAY",
"RCP"
]
}
},
{
"name": "subCode",
"type": {
"name": "subCode",
"type": "enum",
"symbols": [
"PRMR",
"LIST",
"BEN",
"DRBR",
"JNT"
]
}
}
]
}
}
]
}
},
{
"name": "id",
"type": "string",
"doc": "This is the identifier for an instance of customer, which can be related to from other objects."
}
]
}
},
{
"name": "bankAccount",
"type": "record",
"doc": "This object represents the bank account information, required for loan disbursements via ACH.",
"fields": [
{
"name": "accountType",
"type": {
"name": "accountType",
"type": "enum",
"symbols": [
"CHKNG",
"SVNG"
]
}
},
{
"name": "fullName",
"type": "string"
},
{
"name": "bankName",
"type": "string"
},
{
"name": "accountNumber",
"type": "string"
},
{
"name": "routingNumber",
"type": "string"
}
]
},
{
"type": "record",
"name": "trackingeventdetails",
"fields": [
{
"name": "workEventIdent",
"type": [
"string",
"null"
],
"doc": "This field will be populated based on the creation of a tracking work event. This field value holds the key for that particular event."
},
{
"name": "applicationId",
"type": "string"
},
{
"name": "divisionCode",
"type": "string"
},
{
"name": "departmentCode",
"type": "string"
},
{
"name": "workEventNumber",
"type": "int"
},
{
"name": "longComment",
"type": "string"
},
{
"name": "actualEventDate",
"type": "string"
},
{
"name": "priorityCode",
"type": "string"
},
{
"name": "contactTypeCode",
"type": "string"
},
{
"name": "receivedDate",
"type": "string"
},
{
"name": "shortComment",
"type": "string"
},
{
"name": "lastUpdatedBy",
"type": "string"
},
{
"name": "loggedByIdent",
"type": "string"
},
{
"name": "resourceId",
"type": "string"
},
{
"name": "requestOrTypeCode",
"type": "string"
},
{
"name": "serviceChannelSourceCode",
"type": "string"
},
{
"name": "nigoCode",
"type": "string"
},
{
"name": "imageAvailableIndicator",
"type": "string"
},
{
"name": "completionIndicator",
"type": "string"
}
]
},
{
"type": "record",
"name": "policy",
"fields": [
{
"name": "id",
"type": "int"
},
{
"name": "number",
"type": "long"
},
{
"name": "agreementNumberPrefix",
"type": "string"
},
{
"name": "agreementNumberSuffix",
"type": "string"
},
{
"name": "adminSystem",
"type": "string"
}
]
},
{
"type": "record",
"name": "loantransactiondetails",
"doc": "This represents the values specific to the loan transaction.",
"fields": [
{
"name": "transactionAmount",
"type": "string",
"doc": "The amount of the loan."
},
{
"name": "transactionType",
"type": "string"
},
{
"name": "transferAmount",
"type": {
"name": "transferAmount",
"type": "enum",
"symbols": [
"Max",
"Other"
]
}
}
]
}
]
}
],
"type": "record",
"namespace": "com.stream.process",
"name": "loanInitiate"
}
In highlighting search for my application how search works for us is if we pass pageSize it will only return one matching field from record.
For example
There are 4 records
remaining information added in comments as I am unable add code here please advice how can I achieve this requirement
If you need to highlight the result of all matching fields of each document, then you can achieve this in the following way:
Adding a working example with index data, mapping, search query, and search result
Index Mapping:
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter",
"digit"
]
}
}
},
"max_ngram_diff": 50
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "my_analyzer"
},
"lastname": {
"type": "text",
"analyzer": "my_analyzer"
},
"firstname": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
Index Data:
{
"name": "jhon",
"Age": 24,
"lastname": "willam",
"firstname": "henry"
}
{
"name": "kellin",
"Age": 24,
"lastname": "kevin",
"firstname": "mathew"
}
{
"name": "keeper",
"Age": 24,
"lastname": "Jr",
"firstname": "gomez"
}
{
"name": "Asif",
"Age": 24,
"lastname": "peter",
"firstname": "willaim kemp"
}
Search Query:
{
"query": {
"multi_match": {
"query": "ke"
}
},
"highlight": {
"fields": {
"*": {
"type": "plain",
"fragment_size": 20,
"pre_tags": "<span class='bold'>",
"post_tags": "</span>",
"number_of_fragments": 1
}
}
}
}
Search Result:
"hits": [
{
"_index": "64996939",
"_type": "_doc",
"_id": "2",
"_score": 1.1374959,
"_source": {
"name": "kellin",
"Age": 24,
"lastname": "kevin",
"firstname": "mathew"
},
"highlight": {
"name": [
"<span class='bold'>ke</span>llin"
], <-- note this
"lastname": [
"<span class='bold'>ke</span>vin"
]
}
},
{
"_index": "64996939",
"_type": "_doc",
"_id": "4",
"_score": 0.9552834,
"_source": {
"name": "Asif",
"Age": 24,
"lastname": "peter",
"firstname": "willaim kemp"
},
"highlight": {
"firstname": [
"willaim <span class='bold'>ke</span>mp" <-- note this
]
}
},
{
"_index": "64996939",
"_type": "_doc",
"_id": "3",
"_score": 0.62883455,
"_source": {
"name": "keeper",
"Age": 24,
"lastname": "Jr",
"firstname": "gomez"
},
"highlight": {
"name": [
"<span class='bold'>ke</span>eper" <--note this
]
}
}
]
I have the following API defined in my config spec:
"paths": {
"/handler/v1/fetch/{mode}": {
"post": {
"operationId": "ApihandlerFetch",
"parameters": [
{
"name": "mode",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "y",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "m",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "d",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
The following curl requests fails with the error message "global.badrequest"
curl -d '{}' "https://xxxxx.appspot.com/_ah/api/handler/v1/fetch/latest"
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "java.lang.IllegalArgumentException"
}
],
"code": 400,
"message": "java.lang.IllegalArgumentException"
}
}
It however works when the other query parameters are defined with a value like so:
curl -d '' "https://xxxx.appspot.com/_ah/api/handler/v1/fetch/date?y=2017&m=11&d=27"
Did I misunderstood the whole idea of a Query Parameter in Google App Engine Endpoints framework v2, and that the parameters should be part of the URL regardless if they have a value or not (ie: http://...?y=&m=&d).
I have documents like this in the elasticsearch:
{
"_index": "4ccda045-3958-4773-bb34-7af26fa52f4e",
"_type": "jira",
"_id": "BIGHALF-23",
"_score": 1,
"_source": {
"Issue Key": "BIGHALF-23",
"Issuetype Name": "Sub-task",
"Project Name": "Big_Half ",
"Project ID": "10500",
"Project Key": "BIGHALF",
"Workratio": -1,
"Watch Count": 1,
"Created": "2015-10-08T13:12:47",
"Priority": "Medium",
"Assignee Name": "german.solis",
"Assignee EmailAddress": "german.solis#bighalf.io",
"Assignee DisplayName": "German Solis",
"Is Assignee Active": "true",
"Assigne TimeZone": "America/Chicago",
"Updated": "2015-10-19T19:21:22",
"Issue Status": "Done",
"sprint": [{
"Sprint ID": "20",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 11",
"Sprint StartDate": "2015-10-05T01:43:29",
"Sprint EndDate": "2015-10-12T01:43:00",
"Sprint CompleteDate": "2015-10-13T14:31:47"
}, {
"Sprint ID": "23",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 1",
"Sprint StartDate": "2015-10-19T01:47:18",
"Sprint EndDate": "2015-10-26T01:47:00",
"Sprint CompleteDate": "2015-10-24T23:55:22"
}, {
"Sprint ID": "24",
"Sprint State": "CLOSED",
"Sprint Name": "Sprint 2",
"Sprint StartDate": "2015-10-26T11:21:21",
"Sprint EndDate": "2015-11-01T11:21:00",
"Sprint CompleteDate": "2015-11-01T23:06:45"
}],
"Creator Name": "fernando.velazquez",
"Creator EmailAddress": "fernando.velazquez#bighalf.io",
"Creator DisplayName": "fernando.velazquez",
"Creator Active": "false",
"Creator TimeZone": "America/Chicago",
"Reporter Name": "fernando.velazquez",
"Reporter EmailAddress": "fernando.velazquez#bighalf.io",
"Reporter DisplayName": "fernando.velazquez",
"Reporter Active": "false",
"Reporter TimeZone": "America/Chicago",
"Aggregate Progress": 0,
"Aggregate Progress Total": 0,
"Progress": 0,
"Progress Total": 0
}
}
Am applying filter like this using transport client.
{
"bool" : {
"must" : [ {
"nested" : {
"query" : {
"bool" : {
"must" : {
"terms" : {
"sprint.Sprint Name" : [ "Sprint 9" ]
}
}
}
},
"path" : "sprint"
}
}, {
"terms" : {
"Assignee DisplayName" : [ "Mateen Khan" ]
}
} ]
}
}
Even after applying filter Am getting data of other sprints also. which means am getting data for "sprint 7" as well as other sprints also. Am using transport client and also Am performing few complex aggregations with in the same query.
Mappings:
{
"4ccda045-3958-4773-bb34-7af26fa52f4e": {
"mappings": {
"jira": {
"properties": {
"Aggregate Progress": {
"type": "long"
},
"Aggregate Progress Total": {
"type": "long"
},
"Aggregate Progress percent": {
"type": "long"
},
"Aggregate Time Estimate": {
"type": "long"
},
"Aggregate Time Original Estimate": {
"type": "long"
},
"Aggregate Timespent": {
"type": "long"
},
"Assigne TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Assignee DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Assignee EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Assignee Name": {
"type": "string",
"index": "not_analyzed"
},
"Created": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Creator Active": {
"type": "string",
"index": "not_analyzed"
},
"Creator DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Creator EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Creator Name": {
"type": "string",
"index": "not_analyzed"
},
"Creator TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Description": {
"type": "string",
"index": "not_analyzed"
},
"Is Assignee Active": {
"type": "string",
"index": "not_analyzed"
},
"Issue Key": {
"type": "string",
"index": "not_analyzed"
},
"Issue Status": {
"type": "string",
"index": "not_analyzed"
},
"Issuetype Name": {
"type": "string",
"index": "not_analyzed"
},
"Priority": {
"type": "string",
"index": "not_analyzed"
},
"Progress": {
"type": "long"
},
"Progress Percent": {
"type": "long"
},
"Progress Total": {
"type": "long"
},
"Project ID": {
"type": "string",
"index": "not_analyzed"
},
"Project Key": {
"type": "string"
},
"Project Name": {
"type": "string",
"index": "not_analyzed"
},
"Reporter Active": {
"type": "string",
"index": "not_analyzed"
},
"Reporter DisplayName": {
"type": "string",
"index": "not_analyzed"
},
"Reporter EmailAddress": {
"type": "string",
"index": "not_analyzed"
},
"Reporter Name": {
"type": "string",
"index": "not_analyzed"
},
"Reporter TimeZone": {
"type": "string",
"index": "not_analyzed"
},
"Sprint Issue Points": {
"type": "long"
},
"Summary": {
"type": "string",
"index": "not_analyzed"
},
"Time Estimate": {
"type": "long"
},
"Time Original Estimate": {
"type": "long"
},
"Time Tracking Original Estimate": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Original Estimate Seconds": {
"type": "long"
},
"Time Tracking Remaining Estimate": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Remaining Estimate Seconds": {
"type": "long"
},
"Time Tracking Time Spent": {
"type": "string",
"index": "not_analyzed"
},
"Time Tracking Time Spent Seconds": {
"type": "long"
},
"Updated": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Watch Count": {
"type": "long"
},
"Workratio": {
"type": "long"
},
"sprint": {
"type": "nested",
"properties": {
"Sprint CompleteDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint EndDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint ID": {
"type": "string",
"index": "not_analyzed"
},
"Sprint Name": {
"type": "string",
"index": "not_analyzed"
},
"Sprint StartDate": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss"
},
"Sprint State": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
Can you please try replacing terms in must clause by match?
{
"bool" : {
"must" : [ {
"nested" : {
"query" : {
"bool" : {
"must" : {
"match" : {
"sprint.Sprint Name" : [ "Sprint 9" ]
}
}
}
},
"path" : "sprint"
}
}, {
"terms" : {
"Assignee DisplayName" : [ "Mateen Khan" ]
}
} ]
}
}