Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Custom and Generated Code Side by Side with JHipster

1,090 views

Published on

After more than a year of using JHipster for real on several applications, I share the different technics we used to upgrade generated code

Published in: Technology
  • Be the first to comment

Custom and Generated Code Side by Side with JHipster

  1. 1. https://jhipster.tech @java_hipster Custom and Generated Code Side by Side @agoncal
  2. 2. https://jhipster.tech @java_hipster
  3. 3. https://jhipster.tech @java_hipster Website Call for Paper Scheduling Mobile App Ticketing Scanning Digital Signage Tweet wallAccounting Sponsor Venue 3rd party
  4. 4. https://jhipster.tech @java_hipster
  5. 5. https://jhipster.tech @java_hipster Website Call for Paper Scheduling Mobile App Ticketing Scanning Digital Signage Tweet wallAccounting Sponsor Venue 3rd party Grew up organically No communication No SSO No multitenancy No container Fed up of polyglot
  6. 6. https://jhipster.tech @java_hipster
  7. 7. https://jhipster.tech @java_hipster Website Call for Paper Scheduling Mobile App Ticketing Scanning Digital Signage Tweet wallAccounting Sponsor Venue 3rd party Deployer
  8. 8. https://jhipster.tech @java_hipster Patterns We Used Prototype Bootstrap Side by side Quickly test Throw away
  9. 9. https://jhipster.tech @java_hipster Prototype
  10. 10. https://jhipster.tech @java_hipster Prototype JDL
  11. 11. https://jhipster.tech @java_hipster Patterns We Used Prototype Bootstrap Side by side Quickly test Throw away Bootstrap code Bootstrap model Change the generated code
  12. 12. https://jhipster.tech @java_hipster Bootstrap JDL
  13. 13. https://jhipster.tech @java_hipster Patterns We Used Prototype Bootstrap Side by side Quickly test Throw away Bootstrap code Bootstrap model Change the generated code JDL centric Regenerate code frequently Don’t change generated code Develop our own code
  14. 14. https://jhipster.tech @java_hipster Side by Side JDL
  15. 15. https://jhipster.tech @java_hipster Contact/Organisation JDL entity Organisation (spn_organisation) { name String required maxlength(NAME_MAX_LENGTH), description String maxlength(DESCRIPTION_MAX_LENGTH), businessIdentification String, corporateName String, } entity Contact (spn_contact) { firstName String required maxlength(NAME_MAX_LENGTH), lastName String required maxlength(NAME_MAX_LENGTH), email String required minlength(EMAIL_MIN_LENGTH) maxlength(EMAIL_MAX_LENGTH), } relationship OneToMany { Organisation{contacts(lastName)} to Contact{organisation(name) required} }
  16. 16. https://jhipster.tech @java_hipster Contact/Organisation Code organisation .json Domain Contact Organisation 1..* Organisation Repository RepositoryService Organisation Service REST Organisation Resource Angular Organisation Service Organisation /api Organisation Component Organisation Repository Extended Organisation Service Extended Organisation Resource Extended Organisation Service Extended /api/ext Organisation Component Extended organisation- extended.json
  17. 17. https://jhipster.tech @java_hipster Repository @Repository public interface OrganisationRepository extends JpaRepository<Organisation, Long>, JpaSpecificationExecutor<Organisation> { } @Repository public interface OrganisationRepositoryExtended extends OrganisationRepository { @Query("select spn_organisation from Organisation spn_organisation left join fetch spn_organisation.contacts where spn_organisation.id =:id") Optional<Organisation> findOneWithEagerRelationships(@Param("id") Long id); }
  18. 18. https://jhipster.tech @java_hipster Service @Service @Transactional public class OrganisationService { private final OrganisationRepository organisationRepository; public OrganisationService(OrganisationRepository organisationRepository) { this.organisationRepository = organisationRepository; } @Service @Transactional public class OrganisationServiceExtended extends OrganisationService { private final OrganisationRepositoryExtended organisationRepository; public OrganisationServiceExtended(OrganisationRepositoryExtended organisationRepository) { super(organisationRepository); this.organisationRepository = organisationRepository; }
  19. 19. https://jhipster.tech @java_hipster Resource @RestController @RequestMapping("/api") public class OrganisationResource { private final OrganisationService organisationService; @RestController @RequestMapping("/api/extended") public class OrganisationResourceExtended { private final OrganisationServiceExtended organisationService;
  20. 20. https://jhipster.tech @java_hipster Angular Service @Injectable({ providedIn: 'root' }) export class OrganisationService { private resourceUrl = SERVER_API_URL + 'api/organisations'; constructor(private http: HttpClient) {} create(organisation: IOrganisation): Observable<EntityResponseType> { } @Injectable({ providedIn: 'root' }) export class OrganisationExtendedService extends OrganisationService { private resourceUrlExtended = SERVER_API_URL + 'api/extended/organisations'; constructor(private httpExt: HttpClient) { super(httpExt); }
  21. 21. https://jhipster.tech @java_hipster Contact/Organisation Code organisation .json Domain Contact Organisation 1..* Organisation Repository RepositoryService Organisation Service REST Organisation Resource Angular Organisation Service Organisation /api Organisation Component Organisation Repository Extended Organisation Service Extended Organisation Resource Extended Organisation Service Extended /api/ext Organisation Component Extended organisation- extended.json DTO Mapper Exception
  22. 22. https://jhipster.tech @java_hipster First Sprints (development) ● Start with a monolith ● JWT ● Avoid liquibase changeset ● Liquibase context for dev data ● Use Query filters ● Our side-by-side code ○ Components ○ Repositories ○ Services ○ Endpoint
  23. 23. https://jhipster.tech @java_hipster Later Sprints (production) ● Moved to microservices ● Keycloak ● Use liquibase changeset ● Add Gatling / Protractor ● Production in the cloud
  24. 24. https://jhipster.tech @java_hipster Lessons Learnt ● Start will less tech/features, add them later ● Keep JDL up to date ● Never touch generated code ● Keep up with JHipster version ● Use DTO ● Use Query filters ● Run -Pprod builds from start ● Introduce new i18n when needed ● Use PrimeNG components
  25. 25. https://jhipster.tech @java_hipster Lessons Learnt ● PostgreSQL is a fantastic DB (JSon, full text) ● Same DB in dev and prod ● Stick to JHipster ● Docker is good for dev (we don’t use it in prod) ● Reduce the number of technologies ○ Microservices are difficult enough ○ Each new service has a cost in the Cloud
  26. 26. https://jhipster.tech @java_hipster What’s Missing? ● Better directory structure / naming convention ○ Using angularSuffix for now ● Richer model ○ One-to-many unidirectional, Embeddable, List<datatypes> ● More best practices ○ Exception handling in services, Async calls ● Flexible endpoints ○ /api, /internal, /public ● More PostgreSQL support ○ Full text search, JSON
  27. 27. https://jhipster.tech @java_hipster What’s Missing? ● Generate more code with a richer JDL ○ Constants (ending up in Constants.java) ○ Enums (with no entity), helper classes... ○ Repository ○ Service ○ Endpoint ○ Angular services
  28. 28. https://jhipster.tech @java_hipster Contributing back ● Full-text search with PostgreSQL ● Reference data ○ Country (iso2, iso3, name, dial, continent, flag, latitude, longitude, zoom) ○ Language (alpha3b, alpha2, name, flag32) ○ Currency (alphabeticCode, name, numericCode, minorUnit, symbol)
  29. 29. https://jhipster.tech @java_hipster Website Call for Paper Scheduling Mobile App Ticketing Scanning Digital Signage Tweet wallAccounting Sponsor Venue 3rd party Deployer Road Map
  30. 30. https://jhipster.tech @java_hipster Thanks https://github.com/agoncal/agoncal-talks/tree/master/2018-06-JHipsterConf @agoncal

×