Skip to content

Commit

Permalink
WINDUPRULE-934 Added CDI Jakarta technology-tag (#855)
Browse files Browse the repository at this point in the history
(cherry picked from commit dfbbaf8)
  • Loading branch information
mrizzi committed Feb 14, 2023
1 parent ed73c47 commit ec3fa0e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,20 +560,6 @@
</technology-identified>
</perform>
</rule>
<rule id="technology-usage-embedded-framework-05500">
<when>
<graph-query discriminator="TechnologyTagModel">
<property name="name">CDI</property>
</graph-query>
</when>
<perform>
<technology-identified name="CDI">
<tag name="Execute"/>
<tag name="Embedded"/>
<tag name="Inversion of Control"/>
</technology-identified>
</perform>
</rule>
<rule id="technology-usage-embedded-framework-05600">
<when>
<graph-query discriminator="TechnologyTagModel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</perform>
</rule>
<!-- CDI packages references -->
<rule id="javaee-technology-usage-00020">
<rule id="javaee-technology-usage-00020-javax">
<when>
<or>
<javaclass references="javax.enterprise.inject.{*}"/>
Expand All @@ -74,6 +74,17 @@
<technology-tag level="INFORMATIONAL">CDI</technology-tag>
</perform>
</rule>
<rule id="javaee-technology-usage-00020-jakarta">
<when>
<or>
<javaclass references="jakarta.enterprise.inject.{*}"/>
<javaclass references="jakarta.inject.{*}"/>
</or>
</when>
<perform>
<technology-tag level="INFORMATIONAL">CDI</technology-tag>
</perform>
</rule>
<rule id="javaee-technology-usage-00021">
<when>
<graph-query discriminator="TechnologyTagModel">
Expand All @@ -83,7 +94,7 @@
<perform>
<technology-identified name="CDI">
<tag name="Execute"/>
<tag name="Processing"/>
<tag name="Inversion of Control"/>
<tag name="Java EE"/>
</technology-identified>
</perform>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package org.jboss.as.quickstarts.jsonp;

import java.io.StringReader;

import jakarta.enterprise.inject.Model;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Inject;
import jakarta.json.Json;
import jakarta.json.JsonException;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParser.Event;

@Model
public class JsonControllerJakarta {

@Inject
private Person person;

private String jsonString;

private String parsedResult;

public void generateJson() {
jsonString = Json.createObjectBuilder()
.add("name", person.getName())
.add("age", person.getAge())
.add("enabled", person.getEnabled())
.add("phones", Json.createArrayBuilder()
.add(person.getPhone1())
.add(person.getPhone2())
)
.add("addrees", Json.createObjectBuilder()
.add("street", person.getAddressStreet())
.add("apt", person.getAddressApt())
.add("city", person.getAddressCity())
.add("zip", person.getAddressZip())
)
.build().toString();
}

public void parseJsonStream() {
StringBuilder sb = new StringBuilder();
String json = getJsonString();
try {
JsonParser parser = Json.createParser(new StringReader(json));
while (parser.hasNext()) {
Event event = parser.next();
if (event.equals(Event.KEY_NAME)) {
sb.append(" - - - - > Key: " + parser.getString() + " < - - - - - \n");
}
if (event.equals(Event.VALUE_STRING)) {
sb.append("Value as String: " + parser.getString() + "\n");
}
if (event.equals(Event.VALUE_NUMBER)) {
sb.append("Value as Number: " + parser.getInt() + "\n");
}
if (event.equals(Event.VALUE_TRUE)) {
sb.append("Value as Boolean: true\n");
}
if (event.equals(Event.VALUE_FALSE)) {
sb.append("Value as Boolean: false \n");
}
}
} catch (JsonException e) {
FacesContext.getCurrentInstance().addMessage("form:parsed", new FacesMessage(e.getMessage()));
}
parsedResult = sb.toString();
}

public void setJsonString(String jsonString) {
this.jsonString = jsonString;
}

public String getJsonString() {
return jsonString;
}

public String getParsedResult() {
return parsedResult;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -560,20 +560,6 @@
<fail message="Expected data not found for rule technology-usage-embedded-framework-05400"/>
</perform>
</rule>
<rule id="technology-usage-embedded-framework-05500-test">
<when>
<not>
<technology-statistics-exists name="CDI" number-found="1">
<tag name="Execute"/>
<tag name="Embedded"/>
<tag name="Inversion of Control"/>
</technology-statistics-exists>
</not>
</when>
<perform>
<fail message="Expected data not found for rule technology-usage-embedded-framework-05500"/>
</perform>
</rule>
<rule id="technology-usage-embedded-framework-05600-test">
<when>
<not>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<not>
<technology-statistics-exists name="CDI" number-found="1">
<tag name="Execute"/>
<tag name="Processing"/>
<tag name="Inversion of Control"/>
<tag name="Java EE"/>
</technology-statistics-exists>
</not>
Expand Down

0 comments on commit ec3fa0e

Please sign in to comment.