Skip to content

Commit

Permalink
Merge pull request #73 from jGauravGupta/FISH-9548-2
Browse files Browse the repository at this point in the history
FISH-9548 Fixes background error in web console and all rest classes in single package
  • Loading branch information
jGauravGupta authored Oct 18, 2024
2 parents 8ec966f + 6998657 commit a419888
Show file tree
Hide file tree
Showing 24 changed files with 647 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def mpFaultTolerance = request.properties["mpFaultTolerance"].trim()
def mpMetrics = request.properties["mpMetrics"].trim()
def auth = request.properties["auth"].trim()
def erDiagram = request.properties["erDiagram"].trim()
def restSubpackage = request.properties["restSubpackage"].trim()

def outputDirectory = new File(request.getOutputDirectory(), request.getArtifactId())

Expand Down Expand Up @@ -109,6 +110,10 @@ private generateSource(build, _package, platform, jakartaEEVersion,
}

def packagePath = _package.replaceAll("\\.", "/")

File oldFolder = new File(outputDirectory.path + "/src/main/java/" + packagePath + "/resource")
File newFolder = new File(outputDirectory.path + "/src/main/java/" + packagePath + "/" + restSubpackage)
renameFolder(oldFolder, newFolder)

if (!auth.equals("formAuthDB")) {
FileUtils.forceDelete(new File(outputDirectory.path + "/src/main/java/" + packagePath + "/secured/DatabaseSetup.java"))
Expand Down Expand Up @@ -137,6 +142,19 @@ private generateSource(build, _package, platform, jakartaEEVersion,
}
}

private void renameFolder(File oldFolder, File newFolder) {
if (oldFolder.exists() && !newFolder.exists()) {
boolean success = oldFolder.renameTo(newFolder)
if (success) {
println "Folder renamed from ${oldFolder.name} to ${newFolder.name}"
} else {
println "Failed to rename folder ${oldFolder.name}"
}
} else {
println "Folder ${oldFolder.name} does not exist or the new folder ${newFolder.name} already exists."
}
}

private void bindEEPackage(String jakartaEEVersion, String mpConfig, String mpOpenAPI, String mpFaultTolerance, String mpMetrics, String auth, String erDiagram, File outputDirectory) {
def eePackage = (jakartaEEVersion == '8') ? 'javax' : 'jakarta'
println "Binding EE package: $eePackage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
<requiredProperty key="erDiagramName">
<defaultValue></defaultValue>
</requiredProperty>
<requiredProperty key="restSubpackage">
<defaultValue>resource</defaultValue>
</requiredProperty>
</requiredProperties>

<fileSets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ${package}.hello;
package ${package}.${restSubpackage};
<% if (mpConfig) { %>
import ${eePackage}.inject.Inject;<% } %>
import ${eePackage}.ws.rs.GET;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ${package}.hello;
package ${package}.${restSubpackage};

import ${eePackage}.ws.rs.ApplicationPath;
import ${eePackage}.ws.rs.core.Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
import static fish.payara.starter.application.util.StringHelper.startCase;
import static fish.payara.starter.application.util.StringHelper.titleCase;
import jakarta.json.bind.annotation.JsonbTransient;
import jakarta.json.bind.annotation.JsonbTypeSerializer;
import java.util.ArrayList;
import java.util.List;

/**
*
* @author Gaurav Gupta
*/
@JsonbTypeSerializer(AttributeSerializer.class)
public class Attribute {

private String name;
private String type;
private boolean primaryKey;
private boolean required;
private boolean multi;
private boolean required;
private String tooltip;
private Boolean display;
private String htmlLabel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
*
* Copyright (c) 2024 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.starter.application.domain;

import jakarta.json.bind.serializer.JsonbSerializer;
import jakarta.json.bind.serializer.SerializationContext;
import jakarta.json.stream.JsonGenerator;

public class AttributeSerializer implements JsonbSerializer<Attribute> {

@Override
public void serialize(Attribute attribute, JsonGenerator generator, SerializationContext ctx) {
generator.writeStartObject();

// Always write the name and type
generator.write("name", attribute.getName());
generator.write("type", attribute.getType());

if (attribute.isPrimaryKey()) {
generator.write("primaryKey", true);
}
if (attribute.isMulti()) {
generator.write("multi", true);
}

generator.writeEnd();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*
* Copyright (c) 2024 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.starter.application.domain;

Expand All @@ -9,11 +43,11 @@
* @author Gaurav Gupta
*/
public class Constant {
public static final String icon_default = "circle";

public static final String icon_default = "circle";
public static final String title_default = "Jakarta EE Sample";
public static final String longTitle_default = "Jakarta EE Sample";
public static final String homePageDescription_default = "Unlock the full potential of your application by harnessing the power of Jakarta EE";
public static final String aboutUsPageDescription_default = "Welcome to our About Us page, where innovation meets reliability with Payara Jakarta EE. As a team passionate about delivering unparalleled solutions, we specialize in harnessing the power of Jakarta EE to create robust, scalable, and secure applications. With a deep understanding of enterprise-grade development, we are committed to crafting tailored solutions that drive business growth and exceed client expectations. Backed by years of experience and a dedication to staying at the forefront of technology, we take pride in our ability to transform ideas into reality, empowering businesses to thrive in the digital landscape. Discover more about our journey, expertise, and the vision that propels us forward.";

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@
import java.util.ArrayList;
import java.util.List;
import jakarta.json.bind.annotation.JsonbTransient;

import java.util.LinkedHashSet;
import java.util.Set;

public class ERModel {

private List<Entity> entities = new ArrayList<>();
private List<Relationship> relationships = new ArrayList<>();

private Set<Relationship> relationships = new LinkedHashSet<>();

private String icon;
private String title;
private String longTitle;
private String homePageDescription;
private String aboutUsPageDescription;
private List<String> topBarMenuOptions = new ArrayList<>();

public ERModel() {
}
Expand All @@ -59,27 +66,18 @@ public List<Entity> getEntities() {
return entities;
}

public List<Relationship> getRelationships() {
public Set<Relationship> getRelationships() {
return relationships;
}

public void setEntities(List<Entity> entities) {
this.entities = entities;
}

public void setRelationships(List<Relationship> relationships) {
public void setRelationships(Set<Relationship> relationships) {
this.relationships = relationships;
}


private String icon;
private String title;
private String longTitle;
private String homePageDescription;
private String aboutUsPageDescription;
private List<String> topBarMenuOptions = new ArrayList<>();


@JsonbTransient
public String getIcon() {
return icon == null ? icon_default : icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public String getName() {
return name;
}

@JsonbTransient
public String getClassName() {
String[] parts = name.split("_");
StringBuilder result = new StringBuilder();
for (String part : parts) {
if (!part.isEmpty()) {
result.append(part.substring(0, 1).toUpperCase()).append(part.substring(1).toLowerCase());
}
}
return result.toString();
}

@JsonbTransient
public String getStartCaseName() {
return startCase(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package fish.payara.starter.application.domain;

import jakarta.json.bind.annotation.JsonbTransient;
import java.util.List;
import java.util.Objects;

/**
*
Expand Down Expand Up @@ -48,6 +50,28 @@ public String getSecondEntity() {
return secondEntity;
}

@JsonbTransient
public String getFirstEntityClass() {
return getClassName(firstEntity);
}

@JsonbTransient
public String getSecondEntityClass() {
return getClassName(secondEntity);
}

@JsonbTransient
public String getClassName(String name) {
String[] parts = name.split("_");
StringBuilder result = new StringBuilder();
for (String part : parts) {
if (!part.isEmpty()) {
result.append(part.substring(0, 1).toUpperCase()).append(part.substring(1).toLowerCase());
}
}
return result.toString();
}

public String getRelationshipType() {
return relationshipType;
}
Expand Down Expand Up @@ -88,6 +112,35 @@ public void setRelationshipLabel(String relationshipLabel) {
this.relationshipLabel = relationshipLabel;
}

@Override
public int hashCode() {
return Objects.hash(firstEntity, secondEntity, relationshipType, relationshipLabel);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Relationship other = (Relationship)obj;
if (!Objects.equals(this.firstEntity, other.firstEntity)) {
return false;
}
if (!Objects.equals(this.secondEntity, other.secondEntity)) {
return false;
}
if (!Objects.equals(this.relationshipType, other.relationshipType)) {
return false;
}
return Objects.equals(this.relationshipLabel, other.relationshipLabel);
}

@Override
public String toString() {
return "Relationship{" + "firstEntity=" + firstEntity + ", secondEntity=" + secondEntity + ", relationshipType=" + relationshipType + ", relationshipLabel=" + relationshipLabel + '}';
Expand Down
Loading

0 comments on commit a419888

Please sign in to comment.