diff --git a/.jhipster/Company.json b/.jhipster/Company.json new file mode 100644 index 0000000..2d3a63b --- /dev/null +++ b/.jhipster/Company.json @@ -0,0 +1,30 @@ +{ + "name": "Company", + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + } + ], + "relationships": [ + { + "relationshipType": "many-to-one", + "otherEntityName": "company", + "otherEntityRelationshipName": "company", + "relationshipName": "parent", + "otherEntityField": "id" + } + ], + "changelogDate": "20190410224617", + "entityTableName": "company", + "dto": "no", + "pagination": "pagination", + "service": "serviceImpl", + "jpaMetamodelFiltering": false, + "fluentMethods": true, + "clientRootFolder": "", + "applications": "*" +} \ No newline at end of file diff --git a/.jhipster/Station.json b/.jhipster/Station.json new file mode 100644 index 0000000..a51b92b --- /dev/null +++ b/.jhipster/Station.json @@ -0,0 +1,30 @@ +{ + "name": "Station", + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + } + ], + "relationships": [ + { + "relationshipType": "many-to-one", + "otherEntityName": "company", + "otherEntityRelationshipName": "station", + "relationshipName": "company", + "otherEntityField": "id" + } + ], + "changelogDate": "20190410224618", + "entityTableName": "station", + "dto": "no", + "pagination": "no", + "service": "serviceImpl", + "jpaMetamodelFiltering": false, + "fluentMethods": true, + "clientRootFolder": "", + "applications": "*" +} \ No newline at end of file diff --git a/src/main/java/fi/devolon/vitra/domain/Company.java b/src/main/java/fi/devolon/vitra/domain/Company.java new file mode 100644 index 0000000..9360ec0 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/domain/Company.java @@ -0,0 +1,97 @@ +package fi.devolon.vitra.domain; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Field; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.DBRef; +import javax.validation.constraints.*; + +import java.io.Serializable; +import java.util.Objects; + +/** + * A Company. + */ +@Document(collection = "company") +public class Company implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + private String id; + + @NotNull + @Field("name") + private String name; + + @DBRef + @Field("parent") + @JsonIgnoreProperties("companies") + private Company parent; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public Company name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public Company getParent() { + return parent; + } + + public Company parent(Company company) { + this.parent = company; + return this; + } + + public void setParent(Company company) { + this.parent = company; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Company company = (Company) o; + if (company.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), company.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Company{" + + "id=" + getId() + + ", name='" + getName() + "'" + + "}"; + } +} diff --git a/src/main/java/fi/devolon/vitra/domain/Station.java b/src/main/java/fi/devolon/vitra/domain/Station.java new file mode 100644 index 0000000..d948616 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/domain/Station.java @@ -0,0 +1,97 @@ +package fi.devolon.vitra.domain; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Field; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.DBRef; +import javax.validation.constraints.*; + +import java.io.Serializable; +import java.util.Objects; + +/** + * A Station. + */ +@Document(collection = "station") +public class Station implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + private String id; + + @NotNull + @Field("name") + private String name; + + @DBRef + @Field("company") + @JsonIgnoreProperties("stations") + private Company company; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public Station name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public Company getCompany() { + return company; + } + + public Station company(Company company) { + this.company = company; + return this; + } + + public void setCompany(Company company) { + this.company = company; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Station station = (Station) o; + if (station.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), station.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Station{" + + "id=" + getId() + + ", name='" + getName() + "'" + + "}"; + } +} diff --git a/src/main/java/fi/devolon/vitra/repository/CompanyRepository.java b/src/main/java/fi/devolon/vitra/repository/CompanyRepository.java new file mode 100644 index 0000000..f0f133d --- /dev/null +++ b/src/main/java/fi/devolon/vitra/repository/CompanyRepository.java @@ -0,0 +1,16 @@ +package fi.devolon.vitra.repository; + +import fi.devolon.vitra.domain.Company; +import org.springframework.data.mongodb.repository.Query; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + + +/** + * Spring Data MongoDB repository for the Company entity. + */ +@SuppressWarnings("unused") +@Repository +public interface CompanyRepository extends MongoRepository { + +} diff --git a/src/main/java/fi/devolon/vitra/repository/StationRepository.java b/src/main/java/fi/devolon/vitra/repository/StationRepository.java new file mode 100644 index 0000000..c31c296 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/repository/StationRepository.java @@ -0,0 +1,16 @@ +package fi.devolon.vitra.repository; + +import fi.devolon.vitra.domain.Station; +import org.springframework.data.mongodb.repository.Query; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + + +/** + * Spring Data MongoDB repository for the Station entity. + */ +@SuppressWarnings("unused") +@Repository +public interface StationRepository extends MongoRepository { + +} diff --git a/src/main/java/fi/devolon/vitra/service/CompanyService.java b/src/main/java/fi/devolon/vitra/service/CompanyService.java new file mode 100644 index 0000000..3e77a95 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/service/CompanyService.java @@ -0,0 +1,46 @@ +package fi.devolon.vitra.service; + +import fi.devolon.vitra.domain.Company; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.Optional; + +/** + * Service Interface for managing Company. + */ +public interface CompanyService { + + /** + * Save a company. + * + * @param company the entity to save + * @return the persisted entity + */ + Company save(Company company); + + /** + * Get all the companies. + * + * @param pageable the pagination information + * @return the list of entities + */ + Page findAll(Pageable pageable); + + + /** + * Get the "id" company. + * + * @param id the id of the entity + * @return the entity + */ + Optional findOne(String id); + + /** + * Delete the "id" company. + * + * @param id the id of the entity + */ + void delete(String id); +} diff --git a/src/main/java/fi/devolon/vitra/service/StationService.java b/src/main/java/fi/devolon/vitra/service/StationService.java new file mode 100644 index 0000000..7690854 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/service/StationService.java @@ -0,0 +1,43 @@ +package fi.devolon.vitra.service; + +import fi.devolon.vitra.domain.Station; + +import java.util.List; +import java.util.Optional; + +/** + * Service Interface for managing Station. + */ +public interface StationService { + + /** + * Save a station. + * + * @param station the entity to save + * @return the persisted entity + */ + Station save(Station station); + + /** + * Get all the stations. + * + * @return the list of entities + */ + List findAll(); + + + /** + * Get the "id" station. + * + * @param id the id of the entity + * @return the entity + */ + Optional findOne(String id); + + /** + * Delete the "id" station. + * + * @param id the id of the entity + */ + void delete(String id); +} diff --git a/src/main/java/fi/devolon/vitra/service/impl/CompanyServiceImpl.java b/src/main/java/fi/devolon/vitra/service/impl/CompanyServiceImpl.java new file mode 100644 index 0000000..6086bf6 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/service/impl/CompanyServiceImpl.java @@ -0,0 +1,76 @@ +package fi.devolon.vitra.service.impl; + +import fi.devolon.vitra.service.CompanyService; +import fi.devolon.vitra.domain.Company; +import fi.devolon.vitra.repository.CompanyRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +/** + * Service Implementation for managing Company. + */ +@Service +public class CompanyServiceImpl implements CompanyService { + + private final Logger log = LoggerFactory.getLogger(CompanyServiceImpl.class); + + private final CompanyRepository companyRepository; + + public CompanyServiceImpl(CompanyRepository companyRepository) { + this.companyRepository = companyRepository; + } + + /** + * Save a company. + * + * @param company the entity to save + * @return the persisted entity + */ + @Override + public Company save(Company company) { + log.debug("Request to save Company : {}", company); + return companyRepository.save(company); + } + + /** + * Get all the companies. + * + * @param pageable the pagination information + * @return the list of entities + */ + @Override + public Page findAll(Pageable pageable) { + log.debug("Request to get all Companies"); + return companyRepository.findAll(pageable); + } + + + /** + * Get one company by id. + * + * @param id the id of the entity + * @return the entity + */ + @Override + public Optional findOne(String id) { + log.debug("Request to get Company : {}", id); + return companyRepository.findById(id); + } + + /** + * Delete the company by id. + * + * @param id the id of the entity + */ + @Override + public void delete(String id) { + log.debug("Request to delete Company : {}", id); + companyRepository.deleteById(id); + } +} diff --git a/src/main/java/fi/devolon/vitra/service/impl/StationServiceImpl.java b/src/main/java/fi/devolon/vitra/service/impl/StationServiceImpl.java new file mode 100644 index 0000000..c365b4c --- /dev/null +++ b/src/main/java/fi/devolon/vitra/service/impl/StationServiceImpl.java @@ -0,0 +1,74 @@ +package fi.devolon.vitra.service.impl; + +import fi.devolon.vitra.service.StationService; +import fi.devolon.vitra.domain.Station; +import fi.devolon.vitra.repository.StationRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * Service Implementation for managing Station. + */ +@Service +public class StationServiceImpl implements StationService { + + private final Logger log = LoggerFactory.getLogger(StationServiceImpl.class); + + private final StationRepository stationRepository; + + public StationServiceImpl(StationRepository stationRepository) { + this.stationRepository = stationRepository; + } + + /** + * Save a station. + * + * @param station the entity to save + * @return the persisted entity + */ + @Override + public Station save(Station station) { + log.debug("Request to save Station : {}", station); + return stationRepository.save(station); + } + + /** + * Get all the stations. + * + * @return the list of entities + */ + @Override + public List findAll() { + log.debug("Request to get all Stations"); + return stationRepository.findAll(); + } + + + /** + * Get one station by id. + * + * @param id the id of the entity + * @return the entity + */ + @Override + public Optional findOne(String id) { + log.debug("Request to get Station : {}", id); + return stationRepository.findById(id); + } + + /** + * Delete the station by id. + * + * @param id the id of the entity + */ + @Override + public void delete(String id) { + log.debug("Request to delete Station : {}", id); + stationRepository.deleteById(id); + } +} diff --git a/src/main/java/fi/devolon/vitra/web/rest/CompanyResource.java b/src/main/java/fi/devolon/vitra/web/rest/CompanyResource.java new file mode 100644 index 0000000..ff4ff61 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/web/rest/CompanyResource.java @@ -0,0 +1,120 @@ +package fi.devolon.vitra.web.rest; +import fi.devolon.vitra.domain.Company; +import fi.devolon.vitra.service.CompanyService; +import fi.devolon.vitra.web.rest.errors.BadRequestAlertException; +import fi.devolon.vitra.web.rest.util.HeaderUtil; +import fi.devolon.vitra.web.rest.util.PaginationUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Company. + */ +@RestController +@RequestMapping("/api") +public class CompanyResource { + + private final Logger log = LoggerFactory.getLogger(CompanyResource.class); + + private static final String ENTITY_NAME = "company"; + + private final CompanyService companyService; + + public CompanyResource(CompanyService companyService) { + this.companyService = companyService; + } + + /** + * POST /companies : Create a new company. + * + * @param company the company to create + * @return the ResponseEntity with status 201 (Created) and with body the new company, or with status 400 (Bad Request) if the company has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/companies") + public ResponseEntity createCompany(@Valid @RequestBody Company company) throws URISyntaxException { + log.debug("REST request to save Company : {}", company); + if (company.getId() != null) { + throw new BadRequestAlertException("A new company cannot already have an ID", ENTITY_NAME, "idexists"); + } + Company result = companyService.save(company); + return ResponseEntity.created(new URI("/api/companies/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /companies : Updates an existing company. + * + * @param company the company to update + * @return the ResponseEntity with status 200 (OK) and with body the updated company, + * or with status 400 (Bad Request) if the company is not valid, + * or with status 500 (Internal Server Error) if the company couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/companies") + public ResponseEntity updateCompany(@Valid @RequestBody Company company) throws URISyntaxException { + log.debug("REST request to update Company : {}", company); + if (company.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + Company result = companyService.save(company); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, company.getId().toString())) + .body(result); + } + + /** + * GET /companies : get all the companies. + * + * @param pageable the pagination information + * @return the ResponseEntity with status 200 (OK) and the list of companies in body + */ + @GetMapping("/companies") + public ResponseEntity> getAllCompanies(Pageable pageable) { + log.debug("REST request to get a page of Companies"); + Page page = companyService.findAll(pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/companies"); + return ResponseEntity.ok().headers(headers).body(page.getContent()); + } + + /** + * GET /companies/:id : get the "id" company. + * + * @param id the id of the company to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the company, or with status 404 (Not Found) + */ + @GetMapping("/companies/{id}") + public ResponseEntity getCompany(@PathVariable String id) { + log.debug("REST request to get Company : {}", id); + Optional company = companyService.findOne(id); + return ResponseUtil.wrapOrNotFound(company); + } + + /** + * DELETE /companies/:id : delete the "id" company. + * + * @param id the id of the company to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/companies/{id}") + public ResponseEntity deleteCompany(@PathVariable String id) { + log.debug("REST request to delete Company : {}", id); + companyService.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id)).build(); + } +} diff --git a/src/main/java/fi/devolon/vitra/web/rest/StationResource.java b/src/main/java/fi/devolon/vitra/web/rest/StationResource.java new file mode 100644 index 0000000..d51e695 --- /dev/null +++ b/src/main/java/fi/devolon/vitra/web/rest/StationResource.java @@ -0,0 +1,112 @@ +package fi.devolon.vitra.web.rest; +import fi.devolon.vitra.domain.Station; +import fi.devolon.vitra.service.StationService; +import fi.devolon.vitra.web.rest.errors.BadRequestAlertException; +import fi.devolon.vitra.web.rest.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Station. + */ +@RestController +@RequestMapping("/api") +public class StationResource { + + private final Logger log = LoggerFactory.getLogger(StationResource.class); + + private static final String ENTITY_NAME = "station"; + + private final StationService stationService; + + public StationResource(StationService stationService) { + this.stationService = stationService; + } + + /** + * POST /stations : Create a new station. + * + * @param station the station to create + * @return the ResponseEntity with status 201 (Created) and with body the new station, or with status 400 (Bad Request) if the station has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/stations") + public ResponseEntity createStation(@Valid @RequestBody Station station) throws URISyntaxException { + log.debug("REST request to save Station : {}", station); + if (station.getId() != null) { + throw new BadRequestAlertException("A new station cannot already have an ID", ENTITY_NAME, "idexists"); + } + Station result = stationService.save(station); + return ResponseEntity.created(new URI("/api/stations/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /stations : Updates an existing station. + * + * @param station the station to update + * @return the ResponseEntity with status 200 (OK) and with body the updated station, + * or with status 400 (Bad Request) if the station is not valid, + * or with status 500 (Internal Server Error) if the station couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/stations") + public ResponseEntity updateStation(@Valid @RequestBody Station station) throws URISyntaxException { + log.debug("REST request to update Station : {}", station); + if (station.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + Station result = stationService.save(station); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, station.getId().toString())) + .body(result); + } + + /** + * GET /stations : get all the stations. + * + * @return the ResponseEntity with status 200 (OK) and the list of stations in body + */ + @GetMapping("/stations") + public List getAllStations() { + log.debug("REST request to get all Stations"); + return stationService.findAll(); + } + + /** + * GET /stations/:id : get the "id" station. + * + * @param id the id of the station to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the station, or with status 404 (Not Found) + */ + @GetMapping("/stations/{id}") + public ResponseEntity getStation(@PathVariable String id) { + log.debug("REST request to get Station : {}", id); + Optional station = stationService.findOne(id); + return ResponseUtil.wrapOrNotFound(station); + } + + /** + * DELETE /stations/:id : delete the "id" station. + * + * @param id the id of the station to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/stations/{id}") + public ResponseEntity deleteStation(@PathVariable String id) { + log.debug("REST request to delete Station : {}", id); + stationService.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id)).build(); + } +} diff --git a/src/main/webapp/app/entities/company/company-delete-dialog.component.html b/src/main/webapp/app/entities/company/company-delete-dialog.component.html new file mode 100644 index 0000000..a7f70d6 --- /dev/null +++ b/src/main/webapp/app/entities/company/company-delete-dialog.component.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/company/company-delete-dialog.component.ts b/src/main/webapp/app/entities/company/company-delete-dialog.component.ts new file mode 100644 index 0000000..1df6829 --- /dev/null +++ b/src/main/webapp/app/entities/company/company-delete-dialog.component.ts @@ -0,0 +1,65 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { JhiEventManager } from 'ng-jhipster'; + +import { ICompany } from 'app/shared/model/company.model'; +import { CompanyService } from './company.service'; + +@Component({ + selector: 'jhi-company-delete-dialog', + templateUrl: './company-delete-dialog.component.html' +}) +export class CompanyDeleteDialogComponent { + company: ICompany; + + constructor(protected companyService: CompanyService, public activeModal: NgbActiveModal, protected eventManager: JhiEventManager) {} + + clear() { + this.activeModal.dismiss('cancel'); + } + + confirmDelete(id: string) { + this.companyService.delete(id).subscribe(response => { + this.eventManager.broadcast({ + name: 'companyListModification', + content: 'Deleted an company' + }); + this.activeModal.dismiss(true); + }); + } +} + +@Component({ + selector: 'jhi-company-delete-popup', + template: '' +}) +export class CompanyDeletePopupComponent implements OnInit, OnDestroy { + protected ngbModalRef: NgbModalRef; + + constructor(protected activatedRoute: ActivatedRoute, protected router: Router, protected modalService: NgbModal) {} + + ngOnInit() { + this.activatedRoute.data.subscribe(({ company }) => { + setTimeout(() => { + this.ngbModalRef = this.modalService.open(CompanyDeleteDialogComponent as Component, { size: 'lg', backdrop: 'static' }); + this.ngbModalRef.componentInstance.company = company; + this.ngbModalRef.result.then( + result => { + this.router.navigate(['/company', { outlets: { popup: null } }]); + this.ngbModalRef = null; + }, + reason => { + this.router.navigate(['/company', { outlets: { popup: null } }]); + this.ngbModalRef = null; + } + ); + }, 0); + }); + } + + ngOnDestroy() { + this.ngbModalRef = null; + } +} diff --git a/src/main/webapp/app/entities/company/company-detail.component.html b/src/main/webapp/app/entities/company/company-detail.component.html new file mode 100644 index 0000000..032e279 --- /dev/null +++ b/src/main/webapp/app/entities/company/company-detail.component.html @@ -0,0 +1,33 @@ +
+
+
+

Company {{company.id}}

+
+ +
+
Name
+
+ {{company.name}} +
+
Parent
+
+ +
+
+ + + + +
+
+
diff --git a/src/main/webapp/app/entities/company/company-detail.component.ts b/src/main/webapp/app/entities/company/company-detail.component.ts new file mode 100644 index 0000000..869ed39 --- /dev/null +++ b/src/main/webapp/app/entities/company/company-detail.component.ts @@ -0,0 +1,24 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; + +import { ICompany } from 'app/shared/model/company.model'; + +@Component({ + selector: 'jhi-company-detail', + templateUrl: './company-detail.component.html' +}) +export class CompanyDetailComponent implements OnInit { + company: ICompany; + + constructor(protected activatedRoute: ActivatedRoute) {} + + ngOnInit() { + this.activatedRoute.data.subscribe(({ company }) => { + this.company = company; + }); + } + + previousState() { + window.history.back(); + } +} diff --git a/src/main/webapp/app/entities/company/company-update.component.html b/src/main/webapp/app/entities/company/company-update.component.html new file mode 100644 index 0000000..568dd4f --- /dev/null +++ b/src/main/webapp/app/entities/company/company-update.component.html @@ -0,0 +1,42 @@ +
+
+
+

Create or edit a Company

+
+ +
+ + +
+
+ + +
+ + This field is required. + +
+
+ +
+ + +
+
+
+ + +
+
+
+
diff --git a/src/main/webapp/app/entities/company/company-update.component.ts b/src/main/webapp/app/entities/company/company-update.component.ts new file mode 100644 index 0000000..d81e039 --- /dev/null +++ b/src/main/webapp/app/entities/company/company-update.component.ts @@ -0,0 +1,73 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { HttpResponse, HttpErrorResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { JhiAlertService } from 'ng-jhipster'; +import { ICompany } from 'app/shared/model/company.model'; +import { CompanyService } from './company.service'; + +@Component({ + selector: 'jhi-company-update', + templateUrl: './company-update.component.html' +}) +export class CompanyUpdateComponent implements OnInit { + company: ICompany; + isSaving: boolean; + + companies: ICompany[]; + + constructor( + protected jhiAlertService: JhiAlertService, + protected companyService: CompanyService, + protected activatedRoute: ActivatedRoute + ) {} + + ngOnInit() { + this.isSaving = false; + this.activatedRoute.data.subscribe(({ company }) => { + this.company = company; + }); + this.companyService + .query() + .pipe( + filter((mayBeOk: HttpResponse) => mayBeOk.ok), + map((response: HttpResponse) => response.body) + ) + .subscribe((res: ICompany[]) => (this.companies = res), (res: HttpErrorResponse) => this.onError(res.message)); + } + + previousState() { + window.history.back(); + } + + save() { + this.isSaving = true; + if (this.company.id !== undefined) { + this.subscribeToSaveResponse(this.companyService.update(this.company)); + } else { + this.subscribeToSaveResponse(this.companyService.create(this.company)); + } + } + + protected subscribeToSaveResponse(result: Observable>) { + result.subscribe((res: HttpResponse) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError()); + } + + protected onSaveSuccess() { + this.isSaving = false; + this.previousState(); + } + + protected onSaveError() { + this.isSaving = false; + } + + protected onError(errorMessage: string) { + this.jhiAlertService.error(errorMessage, null, null); + } + + trackCompanyById(index: number, item: ICompany) { + return item.id; + } +} diff --git a/src/main/webapp/app/entities/company/company.component.html b/src/main/webapp/app/entities/company/company.component.html new file mode 100644 index 0000000..4ce5b9e --- /dev/null +++ b/src/main/webapp/app/entities/company/company.component.html @@ -0,0 +1,68 @@ +
+

+ Companies + +

+ +
+
+ + + + + + + + + + + + + + + + + +
ID Name Parent
{{company.id}}{{company.name}} + + +
+ + + +
+
+
+
+
+ +
+
+ +
+
+
diff --git a/src/main/webapp/app/entities/company/company.component.ts b/src/main/webapp/app/entities/company/company.component.ts new file mode 100644 index 0000000..3352599 --- /dev/null +++ b/src/main/webapp/app/entities/company/company.component.ts @@ -0,0 +1,131 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster'; + +import { ICompany } from 'app/shared/model/company.model'; +import { AccountService } from 'app/core'; + +import { ITEMS_PER_PAGE } from 'app/shared'; +import { CompanyService } from './company.service'; + +@Component({ + selector: 'jhi-company', + templateUrl: './company.component.html' +}) +export class CompanyComponent implements OnInit, OnDestroy { + currentAccount: any; + companies: ICompany[]; + error: any; + success: any; + eventSubscriber: Subscription; + routeData: any; + links: any; + totalItems: any; + itemsPerPage: any; + page: any; + predicate: any; + previousPage: any; + reverse: any; + + constructor( + protected companyService: CompanyService, + protected parseLinks: JhiParseLinks, + protected jhiAlertService: JhiAlertService, + protected accountService: AccountService, + protected activatedRoute: ActivatedRoute, + protected router: Router, + protected eventManager: JhiEventManager + ) { + this.itemsPerPage = ITEMS_PER_PAGE; + this.routeData = this.activatedRoute.data.subscribe(data => { + this.page = data.pagingParams.page; + this.previousPage = data.pagingParams.page; + this.reverse = data.pagingParams.ascending; + this.predicate = data.pagingParams.predicate; + }); + } + + loadAll() { + this.companyService + .query({ + page: this.page - 1, + size: this.itemsPerPage, + sort: this.sort() + }) + .subscribe( + (res: HttpResponse) => this.paginateCompanies(res.body, res.headers), + (res: HttpErrorResponse) => this.onError(res.message) + ); + } + + loadPage(page: number) { + if (page !== this.previousPage) { + this.previousPage = page; + this.transition(); + } + } + + transition() { + this.router.navigate(['/company'], { + queryParams: { + page: this.page, + size: this.itemsPerPage, + sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc') + } + }); + this.loadAll(); + } + + clear() { + this.page = 0; + this.router.navigate([ + '/company', + { + page: this.page, + sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc') + } + ]); + this.loadAll(); + } + + ngOnInit() { + this.loadAll(); + this.accountService.identity().then(account => { + this.currentAccount = account; + }); + this.registerChangeInCompanies(); + } + + ngOnDestroy() { + this.eventManager.destroy(this.eventSubscriber); + } + + trackId(index: number, item: ICompany) { + return item.id; + } + + registerChangeInCompanies() { + this.eventSubscriber = this.eventManager.subscribe('companyListModification', response => this.loadAll()); + } + + sort() { + const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')]; + if (this.predicate !== 'id') { + result.push('id'); + } + return result; + } + + protected paginateCompanies(data: ICompany[], headers: HttpHeaders) { + this.links = this.parseLinks.parse(headers.get('link')); + this.totalItems = parseInt(headers.get('X-Total-Count'), 10); + this.companies = data; + } + + protected onError(errorMessage: string) { + this.jhiAlertService.error(errorMessage, null, null); + } +} diff --git a/src/main/webapp/app/entities/company/company.module.ts b/src/main/webapp/app/entities/company/company.module.ts new file mode 100644 index 0000000..16f7bdc --- /dev/null +++ b/src/main/webapp/app/entities/company/company.module.ts @@ -0,0 +1,29 @@ +import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import { VirtaSharedModule } from 'app/shared'; +import { + CompanyComponent, + CompanyDetailComponent, + CompanyUpdateComponent, + CompanyDeletePopupComponent, + CompanyDeleteDialogComponent, + companyRoute, + companyPopupRoute +} from './'; + +const ENTITY_STATES = [...companyRoute, ...companyPopupRoute]; + +@NgModule({ + imports: [VirtaSharedModule, RouterModule.forChild(ENTITY_STATES)], + declarations: [ + CompanyComponent, + CompanyDetailComponent, + CompanyUpdateComponent, + CompanyDeleteDialogComponent, + CompanyDeletePopupComponent + ], + entryComponents: [CompanyComponent, CompanyUpdateComponent, CompanyDeleteDialogComponent, CompanyDeletePopupComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] +}) +export class VirtaCompanyModule {} diff --git a/src/main/webapp/app/entities/company/company.route.ts b/src/main/webapp/app/entities/company/company.route.ts new file mode 100644 index 0000000..343be0c --- /dev/null +++ b/src/main/webapp/app/entities/company/company.route.ts @@ -0,0 +1,98 @@ +import { Injectable } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router'; +import { JhiPaginationUtil, JhiResolvePagingParams } from 'ng-jhipster'; +import { UserRouteAccessService } from 'app/core'; +import { Observable, of } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { Company } from 'app/shared/model/company.model'; +import { CompanyService } from './company.service'; +import { CompanyComponent } from './company.component'; +import { CompanyDetailComponent } from './company-detail.component'; +import { CompanyUpdateComponent } from './company-update.component'; +import { CompanyDeletePopupComponent } from './company-delete-dialog.component'; +import { ICompany } from 'app/shared/model/company.model'; + +@Injectable({ providedIn: 'root' }) +export class CompanyResolve implements Resolve { + constructor(private service: CompanyService) {} + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + const id = route.params['id'] ? route.params['id'] : null; + if (id) { + return this.service.find(id).pipe( + filter((response: HttpResponse) => response.ok), + map((company: HttpResponse) => company.body) + ); + } + return of(new Company()); + } +} + +export const companyRoute: Routes = [ + { + path: '', + component: CompanyComponent, + resolve: { + pagingParams: JhiResolvePagingParams + }, + data: { + authorities: ['ROLE_USER'], + defaultSort: 'id,asc', + pageTitle: 'Companies' + }, + canActivate: [UserRouteAccessService] + }, + { + path: ':id/view', + component: CompanyDetailComponent, + resolve: { + company: CompanyResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Companies' + }, + canActivate: [UserRouteAccessService] + }, + { + path: 'new', + component: CompanyUpdateComponent, + resolve: { + company: CompanyResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Companies' + }, + canActivate: [UserRouteAccessService] + }, + { + path: ':id/edit', + component: CompanyUpdateComponent, + resolve: { + company: CompanyResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Companies' + }, + canActivate: [UserRouteAccessService] + } +]; + +export const companyPopupRoute: Routes = [ + { + path: ':id/delete', + component: CompanyDeletePopupComponent, + resolve: { + company: CompanyResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Companies' + }, + canActivate: [UserRouteAccessService], + outlet: 'popup' + } +]; diff --git a/src/main/webapp/app/entities/company/company.service.ts b/src/main/webapp/app/entities/company/company.service.ts new file mode 100644 index 0000000..4603341 --- /dev/null +++ b/src/main/webapp/app/entities/company/company.service.ts @@ -0,0 +1,38 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { SERVER_API_URL } from 'app/app.constants'; +import { createRequestOption } from 'app/shared'; +import { ICompany } from 'app/shared/model/company.model'; + +type EntityResponseType = HttpResponse; +type EntityArrayResponseType = HttpResponse; + +@Injectable({ providedIn: 'root' }) +export class CompanyService { + public resourceUrl = SERVER_API_URL + 'api/companies'; + + constructor(protected http: HttpClient) {} + + create(company: ICompany): Observable { + return this.http.post(this.resourceUrl, company, { observe: 'response' }); + } + + update(company: ICompany): Observable { + return this.http.put(this.resourceUrl, company, { observe: 'response' }); + } + + find(id: string): Observable { + return this.http.get(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } + + query(req?: any): Observable { + const options = createRequestOption(req); + return this.http.get(this.resourceUrl, { params: options, observe: 'response' }); + } + + delete(id: string): Observable> { + return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } +} diff --git a/src/main/webapp/app/entities/company/index.ts b/src/main/webapp/app/entities/company/index.ts new file mode 100644 index 0000000..fa27336 --- /dev/null +++ b/src/main/webapp/app/entities/company/index.ts @@ -0,0 +1,6 @@ +export * from './company.service'; +export * from './company-update.component'; +export * from './company-delete-dialog.component'; +export * from './company-detail.component'; +export * from './company.component'; +export * from './company.route'; diff --git a/src/main/webapp/app/entities/entity.module.ts b/src/main/webapp/app/entities/entity.module.ts index dee26d4..66f98dc 100644 --- a/src/main/webapp/app/entities/entity.module.ts +++ b/src/main/webapp/app/entities/entity.module.ts @@ -4,6 +4,14 @@ import { RouterModule } from '@angular/router'; @NgModule({ imports: [ RouterModule.forChild([ + { + path: 'company', + loadChildren: './company/company.module#VirtaCompanyModule' + }, + { + path: 'station', + loadChildren: './station/station.module#VirtaStationModule' + } /* jhipster-needle-add-entity-route - JHipster will add entity modules routes here */ ]) ], diff --git a/src/main/webapp/app/entities/station/index.ts b/src/main/webapp/app/entities/station/index.ts new file mode 100644 index 0000000..ba976ec --- /dev/null +++ b/src/main/webapp/app/entities/station/index.ts @@ -0,0 +1,6 @@ +export * from './station.service'; +export * from './station-update.component'; +export * from './station-delete-dialog.component'; +export * from './station-detail.component'; +export * from './station.component'; +export * from './station.route'; diff --git a/src/main/webapp/app/entities/station/station-delete-dialog.component.html b/src/main/webapp/app/entities/station/station-delete-dialog.component.html new file mode 100644 index 0000000..0c5259c --- /dev/null +++ b/src/main/webapp/app/entities/station/station-delete-dialog.component.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/station/station-delete-dialog.component.ts b/src/main/webapp/app/entities/station/station-delete-dialog.component.ts new file mode 100644 index 0000000..19a36e6 --- /dev/null +++ b/src/main/webapp/app/entities/station/station-delete-dialog.component.ts @@ -0,0 +1,65 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { JhiEventManager } from 'ng-jhipster'; + +import { IStation } from 'app/shared/model/station.model'; +import { StationService } from './station.service'; + +@Component({ + selector: 'jhi-station-delete-dialog', + templateUrl: './station-delete-dialog.component.html' +}) +export class StationDeleteDialogComponent { + station: IStation; + + constructor(protected stationService: StationService, public activeModal: NgbActiveModal, protected eventManager: JhiEventManager) {} + + clear() { + this.activeModal.dismiss('cancel'); + } + + confirmDelete(id: string) { + this.stationService.delete(id).subscribe(response => { + this.eventManager.broadcast({ + name: 'stationListModification', + content: 'Deleted an station' + }); + this.activeModal.dismiss(true); + }); + } +} + +@Component({ + selector: 'jhi-station-delete-popup', + template: '' +}) +export class StationDeletePopupComponent implements OnInit, OnDestroy { + protected ngbModalRef: NgbModalRef; + + constructor(protected activatedRoute: ActivatedRoute, protected router: Router, protected modalService: NgbModal) {} + + ngOnInit() { + this.activatedRoute.data.subscribe(({ station }) => { + setTimeout(() => { + this.ngbModalRef = this.modalService.open(StationDeleteDialogComponent as Component, { size: 'lg', backdrop: 'static' }); + this.ngbModalRef.componentInstance.station = station; + this.ngbModalRef.result.then( + result => { + this.router.navigate(['/station', { outlets: { popup: null } }]); + this.ngbModalRef = null; + }, + reason => { + this.router.navigate(['/station', { outlets: { popup: null } }]); + this.ngbModalRef = null; + } + ); + }, 0); + }); + } + + ngOnDestroy() { + this.ngbModalRef = null; + } +} diff --git a/src/main/webapp/app/entities/station/station-detail.component.html b/src/main/webapp/app/entities/station/station-detail.component.html new file mode 100644 index 0000000..8460303 --- /dev/null +++ b/src/main/webapp/app/entities/station/station-detail.component.html @@ -0,0 +1,33 @@ +
+
+
+

Station {{station.id}}

+
+ +
+
Name
+
+ {{station.name}} +
+
Company
+
+ +
+
+ + + + +
+
+
diff --git a/src/main/webapp/app/entities/station/station-detail.component.ts b/src/main/webapp/app/entities/station/station-detail.component.ts new file mode 100644 index 0000000..1be2f08 --- /dev/null +++ b/src/main/webapp/app/entities/station/station-detail.component.ts @@ -0,0 +1,24 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; + +import { IStation } from 'app/shared/model/station.model'; + +@Component({ + selector: 'jhi-station-detail', + templateUrl: './station-detail.component.html' +}) +export class StationDetailComponent implements OnInit { + station: IStation; + + constructor(protected activatedRoute: ActivatedRoute) {} + + ngOnInit() { + this.activatedRoute.data.subscribe(({ station }) => { + this.station = station; + }); + } + + previousState() { + window.history.back(); + } +} diff --git a/src/main/webapp/app/entities/station/station-update.component.html b/src/main/webapp/app/entities/station/station-update.component.html new file mode 100644 index 0000000..88410f9 --- /dev/null +++ b/src/main/webapp/app/entities/station/station-update.component.html @@ -0,0 +1,42 @@ +
+
+
+

Create or edit a Station

+
+ +
+ + +
+
+ + +
+ + This field is required. + +
+
+ +
+ + +
+
+
+ + +
+
+
+
diff --git a/src/main/webapp/app/entities/station/station-update.component.ts b/src/main/webapp/app/entities/station/station-update.component.ts new file mode 100644 index 0000000..110135c --- /dev/null +++ b/src/main/webapp/app/entities/station/station-update.component.ts @@ -0,0 +1,76 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { HttpResponse, HttpErrorResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { JhiAlertService } from 'ng-jhipster'; +import { IStation } from 'app/shared/model/station.model'; +import { StationService } from './station.service'; +import { ICompany } from 'app/shared/model/company.model'; +import { CompanyService } from 'app/entities/company'; + +@Component({ + selector: 'jhi-station-update', + templateUrl: './station-update.component.html' +}) +export class StationUpdateComponent implements OnInit { + station: IStation; + isSaving: boolean; + + companies: ICompany[]; + + constructor( + protected jhiAlertService: JhiAlertService, + protected stationService: StationService, + protected companyService: CompanyService, + protected activatedRoute: ActivatedRoute + ) {} + + ngOnInit() { + this.isSaving = false; + this.activatedRoute.data.subscribe(({ station }) => { + this.station = station; + }); + this.companyService + .query() + .pipe( + filter((mayBeOk: HttpResponse) => mayBeOk.ok), + map((response: HttpResponse) => response.body) + ) + .subscribe((res: ICompany[]) => (this.companies = res), (res: HttpErrorResponse) => this.onError(res.message)); + } + + previousState() { + window.history.back(); + } + + save() { + this.isSaving = true; + if (this.station.id !== undefined) { + this.subscribeToSaveResponse(this.stationService.update(this.station)); + } else { + this.subscribeToSaveResponse(this.stationService.create(this.station)); + } + } + + protected subscribeToSaveResponse(result: Observable>) { + result.subscribe((res: HttpResponse) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError()); + } + + protected onSaveSuccess() { + this.isSaving = false; + this.previousState(); + } + + protected onSaveError() { + this.isSaving = false; + } + + protected onError(errorMessage: string) { + this.jhiAlertService.error(errorMessage, null, null); + } + + trackCompanyById(index: number, item: ICompany) { + return item.id; + } +} diff --git a/src/main/webapp/app/entities/station/station.component.html b/src/main/webapp/app/entities/station/station.component.html new file mode 100644 index 0000000..eeb29c7 --- /dev/null +++ b/src/main/webapp/app/entities/station/station.component.html @@ -0,0 +1,60 @@ +
+

+ Stations + +

+ +
+
+ + + + + + + + + + + + + + + + + +
IDNameCompany
{{station.id}}{{station.name}} + + +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/entities/station/station.component.ts b/src/main/webapp/app/entities/station/station.component.ts new file mode 100644 index 0000000..c545bf0 --- /dev/null +++ b/src/main/webapp/app/entities/station/station.component.ts @@ -0,0 +1,65 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { Subscription } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { JhiEventManager, JhiAlertService } from 'ng-jhipster'; + +import { IStation } from 'app/shared/model/station.model'; +import { AccountService } from 'app/core'; +import { StationService } from './station.service'; + +@Component({ + selector: 'jhi-station', + templateUrl: './station.component.html' +}) +export class StationComponent implements OnInit, OnDestroy { + stations: IStation[]; + currentAccount: any; + eventSubscriber: Subscription; + + constructor( + protected stationService: StationService, + protected jhiAlertService: JhiAlertService, + protected eventManager: JhiEventManager, + protected accountService: AccountService + ) {} + + loadAll() { + this.stationService + .query() + .pipe( + filter((res: HttpResponse) => res.ok), + map((res: HttpResponse) => res.body) + ) + .subscribe( + (res: IStation[]) => { + this.stations = res; + }, + (res: HttpErrorResponse) => this.onError(res.message) + ); + } + + ngOnInit() { + this.loadAll(); + this.accountService.identity().then(account => { + this.currentAccount = account; + }); + this.registerChangeInStations(); + } + + ngOnDestroy() { + this.eventManager.destroy(this.eventSubscriber); + } + + trackId(index: number, item: IStation) { + return item.id; + } + + registerChangeInStations() { + this.eventSubscriber = this.eventManager.subscribe('stationListModification', response => this.loadAll()); + } + + protected onError(errorMessage: string) { + this.jhiAlertService.error(errorMessage, null, null); + } +} diff --git a/src/main/webapp/app/entities/station/station.module.ts b/src/main/webapp/app/entities/station/station.module.ts new file mode 100644 index 0000000..d3c1ae8 --- /dev/null +++ b/src/main/webapp/app/entities/station/station.module.ts @@ -0,0 +1,29 @@ +import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import { VirtaSharedModule } from 'app/shared'; +import { + StationComponent, + StationDetailComponent, + StationUpdateComponent, + StationDeletePopupComponent, + StationDeleteDialogComponent, + stationRoute, + stationPopupRoute +} from './'; + +const ENTITY_STATES = [...stationRoute, ...stationPopupRoute]; + +@NgModule({ + imports: [VirtaSharedModule, RouterModule.forChild(ENTITY_STATES)], + declarations: [ + StationComponent, + StationDetailComponent, + StationUpdateComponent, + StationDeleteDialogComponent, + StationDeletePopupComponent + ], + entryComponents: [StationComponent, StationUpdateComponent, StationDeleteDialogComponent, StationDeletePopupComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA] +}) +export class VirtaStationModule {} diff --git a/src/main/webapp/app/entities/station/station.route.ts b/src/main/webapp/app/entities/station/station.route.ts new file mode 100644 index 0000000..2fcf087 --- /dev/null +++ b/src/main/webapp/app/entities/station/station.route.ts @@ -0,0 +1,93 @@ +import { Injectable } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router'; +import { UserRouteAccessService } from 'app/core'; +import { Observable, of } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { Station } from 'app/shared/model/station.model'; +import { StationService } from './station.service'; +import { StationComponent } from './station.component'; +import { StationDetailComponent } from './station-detail.component'; +import { StationUpdateComponent } from './station-update.component'; +import { StationDeletePopupComponent } from './station-delete-dialog.component'; +import { IStation } from 'app/shared/model/station.model'; + +@Injectable({ providedIn: 'root' }) +export class StationResolve implements Resolve { + constructor(private service: StationService) {} + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + const id = route.params['id'] ? route.params['id'] : null; + if (id) { + return this.service.find(id).pipe( + filter((response: HttpResponse) => response.ok), + map((station: HttpResponse) => station.body) + ); + } + return of(new Station()); + } +} + +export const stationRoute: Routes = [ + { + path: '', + component: StationComponent, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Stations' + }, + canActivate: [UserRouteAccessService] + }, + { + path: ':id/view', + component: StationDetailComponent, + resolve: { + station: StationResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Stations' + }, + canActivate: [UserRouteAccessService] + }, + { + path: 'new', + component: StationUpdateComponent, + resolve: { + station: StationResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Stations' + }, + canActivate: [UserRouteAccessService] + }, + { + path: ':id/edit', + component: StationUpdateComponent, + resolve: { + station: StationResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Stations' + }, + canActivate: [UserRouteAccessService] + } +]; + +export const stationPopupRoute: Routes = [ + { + path: ':id/delete', + component: StationDeletePopupComponent, + resolve: { + station: StationResolve + }, + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Stations' + }, + canActivate: [UserRouteAccessService], + outlet: 'popup' + } +]; diff --git a/src/main/webapp/app/entities/station/station.service.ts b/src/main/webapp/app/entities/station/station.service.ts new file mode 100644 index 0000000..72cff4c --- /dev/null +++ b/src/main/webapp/app/entities/station/station.service.ts @@ -0,0 +1,38 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { SERVER_API_URL } from 'app/app.constants'; +import { createRequestOption } from 'app/shared'; +import { IStation } from 'app/shared/model/station.model'; + +type EntityResponseType = HttpResponse; +type EntityArrayResponseType = HttpResponse; + +@Injectable({ providedIn: 'root' }) +export class StationService { + public resourceUrl = SERVER_API_URL + 'api/stations'; + + constructor(protected http: HttpClient) {} + + create(station: IStation): Observable { + return this.http.post(this.resourceUrl, station, { observe: 'response' }); + } + + update(station: IStation): Observable { + return this.http.put(this.resourceUrl, station, { observe: 'response' }); + } + + find(id: string): Observable { + return this.http.get(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } + + query(req?: any): Observable { + const options = createRequestOption(req); + return this.http.get(this.resourceUrl, { params: options, observe: 'response' }); + } + + delete(id: string): Observable> { + return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } +} diff --git a/src/main/webapp/app/layouts/navbar/navbar.component.html b/src/main/webapp/app/layouts/navbar/navbar.component.html index a72f29f..41c5654 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.component.html +++ b/src/main/webapp/app/layouts/navbar/navbar.component.html @@ -27,6 +27,18 @@ diff --git a/src/main/webapp/app/shared/model/company.model.ts b/src/main/webapp/app/shared/model/company.model.ts new file mode 100644 index 0000000..b830b12 --- /dev/null +++ b/src/main/webapp/app/shared/model/company.model.ts @@ -0,0 +1,11 @@ +import { ICompany } from 'app/shared/model/company.model'; + +export interface ICompany { + id?: string; + name?: string; + parent?: ICompany; +} + +export class Company implements ICompany { + constructor(public id?: string, public name?: string, public parent?: ICompany) {} +} diff --git a/src/main/webapp/app/shared/model/station.model.ts b/src/main/webapp/app/shared/model/station.model.ts new file mode 100644 index 0000000..cf4cc4e --- /dev/null +++ b/src/main/webapp/app/shared/model/station.model.ts @@ -0,0 +1,11 @@ +import { ICompany } from 'app/shared/model/company.model'; + +export interface IStation { + id?: string; + name?: string; + company?: ICompany; +} + +export class Station implements IStation { + constructor(public id?: string, public name?: string, public company?: ICompany) {} +} diff --git a/src/test/java/fi/devolon/vitra/web/rest/CompanyResourceIntTest.java b/src/test/java/fi/devolon/vitra/web/rest/CompanyResourceIntTest.java new file mode 100644 index 0000000..e5e21af --- /dev/null +++ b/src/test/java/fi/devolon/vitra/web/rest/CompanyResourceIntTest.java @@ -0,0 +1,253 @@ +package fi.devolon.vitra.web.rest; + +import fi.devolon.vitra.VirtaApp; + +import fi.devolon.vitra.domain.Company; +import fi.devolon.vitra.repository.CompanyRepository; +import fi.devolon.vitra.service.CompanyService; +import fi.devolon.vitra.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.validation.Validator; + +import java.util.List; + + +import static fi.devolon.vitra.web.rest.TestUtil.createFormattingConversionService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the CompanyResource REST controller. + * + * @see CompanyResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VirtaApp.class) +public class CompanyResourceIntTest { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + @Autowired + private CompanyRepository companyRepository; + + @Autowired + private CompanyService companyService; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private Validator validator; + + private MockMvc restCompanyMockMvc; + + private Company company; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final CompanyResource companyResource = new CompanyResource(companyService); + this.restCompanyMockMvc = MockMvcBuilders.standaloneSetup(companyResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setConversionService(createFormattingConversionService()) + .setMessageConverters(jacksonMessageConverter) + .setValidator(validator).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Company createEntity() { + Company company = new Company() + .name(DEFAULT_NAME); + return company; + } + + @Before + public void initTest() { + companyRepository.deleteAll(); + company = createEntity(); + } + + @Test + public void createCompany() throws Exception { + int databaseSizeBeforeCreate = companyRepository.findAll().size(); + + // Create the Company + restCompanyMockMvc.perform(post("/api/companies") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(company))) + .andExpect(status().isCreated()); + + // Validate the Company in the database + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeCreate + 1); + Company testCompany = companyList.get(companyList.size() - 1); + assertThat(testCompany.getName()).isEqualTo(DEFAULT_NAME); + } + + @Test + public void createCompanyWithExistingId() throws Exception { + int databaseSizeBeforeCreate = companyRepository.findAll().size(); + + // Create the Company with an existing ID + company.setId("existing_id"); + + // An entity with an existing ID cannot be created, so this API call must fail + restCompanyMockMvc.perform(post("/api/companies") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(company))) + .andExpect(status().isBadRequest()); + + // Validate the Company in the database + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeCreate); + } + + @Test + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = companyRepository.findAll().size(); + // set the field null + company.setName(null); + + // Create the Company, which fails. + + restCompanyMockMvc.perform(post("/api/companies") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(company))) + .andExpect(status().isBadRequest()); + + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeTest); + } + + @Test + public void getAllCompanies() throws Exception { + // Initialize the database + companyRepository.save(company); + + // Get all the companyList + restCompanyMockMvc.perform(get("/api/companies?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(company.getId()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))); + } + + @Test + public void getCompany() throws Exception { + // Initialize the database + companyRepository.save(company); + + // Get the company + restCompanyMockMvc.perform(get("/api/companies/{id}", company.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(company.getId())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())); + } + + @Test + public void getNonExistingCompany() throws Exception { + // Get the company + restCompanyMockMvc.perform(get("/api/companies/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + public void updateCompany() throws Exception { + // Initialize the database + companyService.save(company); + + int databaseSizeBeforeUpdate = companyRepository.findAll().size(); + + // Update the company + Company updatedCompany = companyRepository.findById(company.getId()).get(); + updatedCompany + .name(UPDATED_NAME); + + restCompanyMockMvc.perform(put("/api/companies") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedCompany))) + .andExpect(status().isOk()); + + // Validate the Company in the database + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeUpdate); + Company testCompany = companyList.get(companyList.size() - 1); + assertThat(testCompany.getName()).isEqualTo(UPDATED_NAME); + } + + @Test + public void updateNonExistingCompany() throws Exception { + int databaseSizeBeforeUpdate = companyRepository.findAll().size(); + + // Create the Company + + // If the entity doesn't have an ID, it will throw BadRequestAlertException + restCompanyMockMvc.perform(put("/api/companies") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(company))) + .andExpect(status().isBadRequest()); + + // Validate the Company in the database + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeUpdate); + } + + @Test + public void deleteCompany() throws Exception { + // Initialize the database + companyService.save(company); + + int databaseSizeBeforeDelete = companyRepository.findAll().size(); + + // Delete the company + restCompanyMockMvc.perform(delete("/api/companies/{id}", company.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List companyList = companyRepository.findAll(); + assertThat(companyList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Company.class); + Company company1 = new Company(); + company1.setId("id1"); + Company company2 = new Company(); + company2.setId(company1.getId()); + assertThat(company1).isEqualTo(company2); + company2.setId("id2"); + assertThat(company1).isNotEqualTo(company2); + company1.setId(null); + assertThat(company1).isNotEqualTo(company2); + } +} diff --git a/src/test/java/fi/devolon/vitra/web/rest/StationResourceIntTest.java b/src/test/java/fi/devolon/vitra/web/rest/StationResourceIntTest.java new file mode 100644 index 0000000..6e740c0 --- /dev/null +++ b/src/test/java/fi/devolon/vitra/web/rest/StationResourceIntTest.java @@ -0,0 +1,253 @@ +package fi.devolon.vitra.web.rest; + +import fi.devolon.vitra.VirtaApp; + +import fi.devolon.vitra.domain.Station; +import fi.devolon.vitra.repository.StationRepository; +import fi.devolon.vitra.service.StationService; +import fi.devolon.vitra.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.validation.Validator; + +import java.util.List; + + +import static fi.devolon.vitra.web.rest.TestUtil.createFormattingConversionService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the StationResource REST controller. + * + * @see StationResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VirtaApp.class) +public class StationResourceIntTest { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + @Autowired + private StationRepository stationRepository; + + @Autowired + private StationService stationService; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private Validator validator; + + private MockMvc restStationMockMvc; + + private Station station; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final StationResource stationResource = new StationResource(stationService); + this.restStationMockMvc = MockMvcBuilders.standaloneSetup(stationResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setConversionService(createFormattingConversionService()) + .setMessageConverters(jacksonMessageConverter) + .setValidator(validator).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Station createEntity() { + Station station = new Station() + .name(DEFAULT_NAME); + return station; + } + + @Before + public void initTest() { + stationRepository.deleteAll(); + station = createEntity(); + } + + @Test + public void createStation() throws Exception { + int databaseSizeBeforeCreate = stationRepository.findAll().size(); + + // Create the Station + restStationMockMvc.perform(post("/api/stations") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(station))) + .andExpect(status().isCreated()); + + // Validate the Station in the database + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeCreate + 1); + Station testStation = stationList.get(stationList.size() - 1); + assertThat(testStation.getName()).isEqualTo(DEFAULT_NAME); + } + + @Test + public void createStationWithExistingId() throws Exception { + int databaseSizeBeforeCreate = stationRepository.findAll().size(); + + // Create the Station with an existing ID + station.setId("existing_id"); + + // An entity with an existing ID cannot be created, so this API call must fail + restStationMockMvc.perform(post("/api/stations") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(station))) + .andExpect(status().isBadRequest()); + + // Validate the Station in the database + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeCreate); + } + + @Test + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = stationRepository.findAll().size(); + // set the field null + station.setName(null); + + // Create the Station, which fails. + + restStationMockMvc.perform(post("/api/stations") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(station))) + .andExpect(status().isBadRequest()); + + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeTest); + } + + @Test + public void getAllStations() throws Exception { + // Initialize the database + stationRepository.save(station); + + // Get all the stationList + restStationMockMvc.perform(get("/api/stations?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(station.getId()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))); + } + + @Test + public void getStation() throws Exception { + // Initialize the database + stationRepository.save(station); + + // Get the station + restStationMockMvc.perform(get("/api/stations/{id}", station.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(station.getId())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())); + } + + @Test + public void getNonExistingStation() throws Exception { + // Get the station + restStationMockMvc.perform(get("/api/stations/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + public void updateStation() throws Exception { + // Initialize the database + stationService.save(station); + + int databaseSizeBeforeUpdate = stationRepository.findAll().size(); + + // Update the station + Station updatedStation = stationRepository.findById(station.getId()).get(); + updatedStation + .name(UPDATED_NAME); + + restStationMockMvc.perform(put("/api/stations") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedStation))) + .andExpect(status().isOk()); + + // Validate the Station in the database + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeUpdate); + Station testStation = stationList.get(stationList.size() - 1); + assertThat(testStation.getName()).isEqualTo(UPDATED_NAME); + } + + @Test + public void updateNonExistingStation() throws Exception { + int databaseSizeBeforeUpdate = stationRepository.findAll().size(); + + // Create the Station + + // If the entity doesn't have an ID, it will throw BadRequestAlertException + restStationMockMvc.perform(put("/api/stations") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(station))) + .andExpect(status().isBadRequest()); + + // Validate the Station in the database + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeUpdate); + } + + @Test + public void deleteStation() throws Exception { + // Initialize the database + stationService.save(station); + + int databaseSizeBeforeDelete = stationRepository.findAll().size(); + + // Delete the station + restStationMockMvc.perform(delete("/api/stations/{id}", station.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List stationList = stationRepository.findAll(); + assertThat(stationList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Station.class); + Station station1 = new Station(); + station1.setId("id1"); + Station station2 = new Station(); + station2.setId(station1.getId()); + assertThat(station1).isEqualTo(station2); + station2.setId("id2"); + assertThat(station1).isNotEqualTo(station2); + station1.setId(null); + assertThat(station1).isNotEqualTo(station2); + } +} diff --git a/src/test/javascript/spec/app/entities/company/company-delete-dialog.component.spec.ts b/src/test/javascript/spec/app/entities/company/company-delete-dialog.component.spec.ts new file mode 100644 index 0000000..70f3377 --- /dev/null +++ b/src/test/javascript/spec/app/entities/company/company-delete-dialog.component.spec.ts @@ -0,0 +1,52 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { Observable, of } from 'rxjs'; +import { JhiEventManager } from 'ng-jhipster'; + +import { VirtaTestModule } from '../../../test.module'; +import { CompanyDeleteDialogComponent } from 'app/entities/company/company-delete-dialog.component'; +import { CompanyService } from 'app/entities/company/company.service'; + +describe('Component Tests', () => { + describe('Company Management Delete Component', () => { + let comp: CompanyDeleteDialogComponent; + let fixture: ComponentFixture; + let service: CompanyService; + let mockEventManager: any; + let mockActiveModal: any; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [CompanyDeleteDialogComponent] + }) + .overrideTemplate(CompanyDeleteDialogComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(CompanyDeleteDialogComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(CompanyService); + mockEventManager = fixture.debugElement.injector.get(JhiEventManager); + mockActiveModal = fixture.debugElement.injector.get(NgbActiveModal); + }); + + describe('confirmDelete', () => { + it('Should call delete service on confirmDelete', inject( + [], + fakeAsync(() => { + // GIVEN + spyOn(service, 'delete').and.returnValue(of({})); + + // WHEN + comp.confirmDelete('123'); + tick(); + + // THEN + expect(service.delete).toHaveBeenCalledWith('123'); + expect(mockActiveModal.dismissSpy).toHaveBeenCalled(); + expect(mockEventManager.broadcastSpy).toHaveBeenCalled(); + }) + )); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/company/company-detail.component.spec.ts b/src/test/javascript/spec/app/entities/company/company-detail.component.spec.ts new file mode 100644 index 0000000..cba725d --- /dev/null +++ b/src/test/javascript/spec/app/entities/company/company-detail.component.spec.ts @@ -0,0 +1,40 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { of } from 'rxjs'; + +import { VirtaTestModule } from '../../../test.module'; +import { CompanyDetailComponent } from 'app/entities/company/company-detail.component'; +import { Company } from 'app/shared/model/company.model'; + +describe('Component Tests', () => { + describe('Company Management Detail Component', () => { + let comp: CompanyDetailComponent; + let fixture: ComponentFixture; + const route = ({ data: of({ company: new Company('123') }) } as any) as ActivatedRoute; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [CompanyDetailComponent], + providers: [{ provide: ActivatedRoute, useValue: route }] + }) + .overrideTemplate(CompanyDetailComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(CompanyDetailComponent); + comp = fixture.componentInstance; + }); + + describe('OnInit', () => { + it('Should call load all on init', () => { + // GIVEN + + // WHEN + comp.ngOnInit(); + + // THEN + expect(comp.company).toEqual(jasmine.objectContaining({ id: '123' })); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/company/company-update.component.spec.ts b/src/test/javascript/spec/app/entities/company/company-update.component.spec.ts new file mode 100644 index 0000000..2bff288 --- /dev/null +++ b/src/test/javascript/spec/app/entities/company/company-update.component.spec.ts @@ -0,0 +1,66 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; +import { HttpResponse } from '@angular/common/http'; +import { Observable, of } from 'rxjs'; + +import { VirtaTestModule } from '../../../test.module'; +import { CompanyUpdateComponent } from 'app/entities/company/company-update.component'; +import { CompanyService } from 'app/entities/company/company.service'; +import { Company } from 'app/shared/model/company.model'; + +describe('Component Tests', () => { + describe('Company Management Update Component', () => { + let comp: CompanyUpdateComponent; + let fixture: ComponentFixture; + let service: CompanyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [CompanyUpdateComponent] + }) + .overrideTemplate(CompanyUpdateComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(CompanyUpdateComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(CompanyService); + }); + + describe('save', () => { + it( + 'Should call update service on save for existing entity', + fakeAsync(() => { + // GIVEN + const entity = new Company('123'); + spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.company = entity; + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.update).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + }) + ); + + it( + 'Should call create service on save for new entity', + fakeAsync(() => { + // GIVEN + const entity = new Company(); + spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.company = entity; + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.create).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + }) + ); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/company/company.component.spec.ts b/src/test/javascript/spec/app/entities/company/company.component.spec.ts new file mode 100644 index 0000000..414c248 --- /dev/null +++ b/src/test/javascript/spec/app/entities/company/company.component.spec.ts @@ -0,0 +1,138 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable, of } from 'rxjs'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; +import { ActivatedRoute, Data } from '@angular/router'; + +import { VirtaTestModule } from '../../../test.module'; +import { CompanyComponent } from 'app/entities/company/company.component'; +import { CompanyService } from 'app/entities/company/company.service'; +import { Company } from 'app/shared/model/company.model'; + +describe('Component Tests', () => { + describe('Company Management Component', () => { + let comp: CompanyComponent; + let fixture: ComponentFixture; + let service: CompanyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [CompanyComponent], + providers: [ + { + provide: ActivatedRoute, + useValue: { + data: { + subscribe: (fn: (value: Data) => void) => + fn({ + pagingParams: { + predicate: 'id', + reverse: false, + page: 0 + } + }) + } + } + } + ] + }) + .overrideTemplate(CompanyComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(CompanyComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(CompanyService); + }); + + it('Should call load all on init', () => { + // GIVEN + const headers = new HttpHeaders().append('link', 'link;link'); + spyOn(service, 'query').and.returnValue( + of( + new HttpResponse({ + body: [new Company('123')], + headers + }) + ) + ); + + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.companies[0]).toEqual(jasmine.objectContaining({ id: '123' })); + }); + + it('should load a page', () => { + // GIVEN + const headers = new HttpHeaders().append('link', 'link;link'); + spyOn(service, 'query').and.returnValue( + of( + new HttpResponse({ + body: [new Company('123')], + headers + }) + ) + ); + + // WHEN + comp.loadPage(1); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.companies[0]).toEqual(jasmine.objectContaining({ id: '123' })); + }); + + it('should not load a page is the page is the same as the previous page', () => { + spyOn(service, 'query').and.callThrough(); + + // WHEN + comp.loadPage(0); + + // THEN + expect(service.query).toHaveBeenCalledTimes(0); + }); + + it('should re-initialize the page', () => { + // GIVEN + const headers = new HttpHeaders().append('link', 'link;link'); + spyOn(service, 'query').and.returnValue( + of( + new HttpResponse({ + body: [new Company('123')], + headers + }) + ) + ); + + // WHEN + comp.loadPage(1); + comp.clear(); + + // THEN + expect(comp.page).toEqual(0); + expect(service.query).toHaveBeenCalledTimes(2); + expect(comp.companies[0]).toEqual(jasmine.objectContaining({ id: '123' })); + }); + it('should calculate the sort attribute for an id', () => { + // WHEN + const result = comp.sort(); + + // THEN + expect(result).toEqual(['id,desc']); + }); + + it('should calculate the sort attribute for a non-id attribute', () => { + // GIVEN + comp.predicate = 'name'; + + // WHEN + const result = comp.sort(); + + // THEN + expect(result).toEqual(['name,desc', 'id']); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/company/company.service.spec.ts b/src/test/javascript/spec/app/entities/company/company.service.spec.ts new file mode 100644 index 0000000..22377c5 --- /dev/null +++ b/src/test/javascript/spec/app/entities/company/company.service.spec.ts @@ -0,0 +1,104 @@ +/* tslint:disable max-line-length */ +import { TestBed, getTestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { of } from 'rxjs'; +import { take, map } from 'rxjs/operators'; +import { CompanyService } from 'app/entities/company/company.service'; +import { ICompany, Company } from 'app/shared/model/company.model'; + +describe('Service Tests', () => { + describe('Company Service', () => { + let injector: TestBed; + let service: CompanyService; + let httpMock: HttpTestingController; + let elemDefault: ICompany; + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule] + }); + injector = getTestBed(); + service = injector.get(CompanyService); + httpMock = injector.get(HttpTestingController); + + elemDefault = new Company('ID', 'AAAAAAA'); + }); + + describe('Service methods', async () => { + it('should find an element', async () => { + const returnedFromService = Object.assign({}, elemDefault); + service + .find('123') + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: elemDefault })); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should create a Company', async () => { + const returnedFromService = Object.assign( + { + id: 'ID' + }, + elemDefault + ); + const expected = Object.assign({}, returnedFromService); + service + .create(new Company(null)) + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: expected })); + const req = httpMock.expectOne({ method: 'POST' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should update a Company', async () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB' + }, + elemDefault + ); + + const expected = Object.assign({}, returnedFromService); + service + .update(expected) + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: expected })); + const req = httpMock.expectOne({ method: 'PUT' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should return a list of Company', async () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB' + }, + elemDefault + ); + const expected = Object.assign({}, returnedFromService); + service + .query(expected) + .pipe( + take(1), + map(resp => resp.body) + ) + .subscribe(body => expect(body).toContainEqual(expected)); + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(JSON.stringify([returnedFromService])); + httpMock.verify(); + }); + + it('should delete a Company', async () => { + const rxPromise = service.delete('123').subscribe(resp => expect(resp.ok)); + + const req = httpMock.expectOne({ method: 'DELETE' }); + req.flush({ status: 200 }); + }); + }); + + afterEach(() => { + httpMock.verify(); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/station/station-delete-dialog.component.spec.ts b/src/test/javascript/spec/app/entities/station/station-delete-dialog.component.spec.ts new file mode 100644 index 0000000..8cd82bd --- /dev/null +++ b/src/test/javascript/spec/app/entities/station/station-delete-dialog.component.spec.ts @@ -0,0 +1,52 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { Observable, of } from 'rxjs'; +import { JhiEventManager } from 'ng-jhipster'; + +import { VirtaTestModule } from '../../../test.module'; +import { StationDeleteDialogComponent } from 'app/entities/station/station-delete-dialog.component'; +import { StationService } from 'app/entities/station/station.service'; + +describe('Component Tests', () => { + describe('Station Management Delete Component', () => { + let comp: StationDeleteDialogComponent; + let fixture: ComponentFixture; + let service: StationService; + let mockEventManager: any; + let mockActiveModal: any; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [StationDeleteDialogComponent] + }) + .overrideTemplate(StationDeleteDialogComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(StationDeleteDialogComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(StationService); + mockEventManager = fixture.debugElement.injector.get(JhiEventManager); + mockActiveModal = fixture.debugElement.injector.get(NgbActiveModal); + }); + + describe('confirmDelete', () => { + it('Should call delete service on confirmDelete', inject( + [], + fakeAsync(() => { + // GIVEN + spyOn(service, 'delete').and.returnValue(of({})); + + // WHEN + comp.confirmDelete('123'); + tick(); + + // THEN + expect(service.delete).toHaveBeenCalledWith('123'); + expect(mockActiveModal.dismissSpy).toHaveBeenCalled(); + expect(mockEventManager.broadcastSpy).toHaveBeenCalled(); + }) + )); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/station/station-detail.component.spec.ts b/src/test/javascript/spec/app/entities/station/station-detail.component.spec.ts new file mode 100644 index 0000000..756a410 --- /dev/null +++ b/src/test/javascript/spec/app/entities/station/station-detail.component.spec.ts @@ -0,0 +1,40 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { of } from 'rxjs'; + +import { VirtaTestModule } from '../../../test.module'; +import { StationDetailComponent } from 'app/entities/station/station-detail.component'; +import { Station } from 'app/shared/model/station.model'; + +describe('Component Tests', () => { + describe('Station Management Detail Component', () => { + let comp: StationDetailComponent; + let fixture: ComponentFixture; + const route = ({ data: of({ station: new Station('123') }) } as any) as ActivatedRoute; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [StationDetailComponent], + providers: [{ provide: ActivatedRoute, useValue: route }] + }) + .overrideTemplate(StationDetailComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(StationDetailComponent); + comp = fixture.componentInstance; + }); + + describe('OnInit', () => { + it('Should call load all on init', () => { + // GIVEN + + // WHEN + comp.ngOnInit(); + + // THEN + expect(comp.station).toEqual(jasmine.objectContaining({ id: '123' })); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/station/station-update.component.spec.ts b/src/test/javascript/spec/app/entities/station/station-update.component.spec.ts new file mode 100644 index 0000000..a885bc6 --- /dev/null +++ b/src/test/javascript/spec/app/entities/station/station-update.component.spec.ts @@ -0,0 +1,66 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; +import { HttpResponse } from '@angular/common/http'; +import { Observable, of } from 'rxjs'; + +import { VirtaTestModule } from '../../../test.module'; +import { StationUpdateComponent } from 'app/entities/station/station-update.component'; +import { StationService } from 'app/entities/station/station.service'; +import { Station } from 'app/shared/model/station.model'; + +describe('Component Tests', () => { + describe('Station Management Update Component', () => { + let comp: StationUpdateComponent; + let fixture: ComponentFixture; + let service: StationService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [StationUpdateComponent] + }) + .overrideTemplate(StationUpdateComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(StationUpdateComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(StationService); + }); + + describe('save', () => { + it( + 'Should call update service on save for existing entity', + fakeAsync(() => { + // GIVEN + const entity = new Station('123'); + spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.station = entity; + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.update).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + }) + ); + + it( + 'Should call create service on save for new entity', + fakeAsync(() => { + // GIVEN + const entity = new Station(); + spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.station = entity; + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.create).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + }) + ); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/station/station.component.spec.ts b/src/test/javascript/spec/app/entities/station/station.component.spec.ts new file mode 100644 index 0000000..15ebcb6 --- /dev/null +++ b/src/test/javascript/spec/app/entities/station/station.component.spec.ts @@ -0,0 +1,51 @@ +/* tslint:disable max-line-length */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable, of } from 'rxjs'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; + +import { VirtaTestModule } from '../../../test.module'; +import { StationComponent } from 'app/entities/station/station.component'; +import { StationService } from 'app/entities/station/station.service'; +import { Station } from 'app/shared/model/station.model'; + +describe('Component Tests', () => { + describe('Station Management Component', () => { + let comp: StationComponent; + let fixture: ComponentFixture; + let service: StationService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VirtaTestModule], + declarations: [StationComponent], + providers: [] + }) + .overrideTemplate(StationComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(StationComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(StationService); + }); + + it('Should call load all on init', () => { + // GIVEN + const headers = new HttpHeaders().append('link', 'link;link'); + spyOn(service, 'query').and.returnValue( + of( + new HttpResponse({ + body: [new Station('123')], + headers + }) + ) + ); + + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.stations[0]).toEqual(jasmine.objectContaining({ id: '123' })); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/station/station.service.spec.ts b/src/test/javascript/spec/app/entities/station/station.service.spec.ts new file mode 100644 index 0000000..34e925d --- /dev/null +++ b/src/test/javascript/spec/app/entities/station/station.service.spec.ts @@ -0,0 +1,104 @@ +/* tslint:disable max-line-length */ +import { TestBed, getTestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { of } from 'rxjs'; +import { take, map } from 'rxjs/operators'; +import { StationService } from 'app/entities/station/station.service'; +import { IStation, Station } from 'app/shared/model/station.model'; + +describe('Service Tests', () => { + describe('Station Service', () => { + let injector: TestBed; + let service: StationService; + let httpMock: HttpTestingController; + let elemDefault: IStation; + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule] + }); + injector = getTestBed(); + service = injector.get(StationService); + httpMock = injector.get(HttpTestingController); + + elemDefault = new Station('ID', 'AAAAAAA'); + }); + + describe('Service methods', async () => { + it('should find an element', async () => { + const returnedFromService = Object.assign({}, elemDefault); + service + .find('123') + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: elemDefault })); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should create a Station', async () => { + const returnedFromService = Object.assign( + { + id: 'ID' + }, + elemDefault + ); + const expected = Object.assign({}, returnedFromService); + service + .create(new Station(null)) + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: expected })); + const req = httpMock.expectOne({ method: 'POST' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should update a Station', async () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB' + }, + elemDefault + ); + + const expected = Object.assign({}, returnedFromService); + service + .update(expected) + .pipe(take(1)) + .subscribe(resp => expect(resp).toMatchObject({ body: expected })); + const req = httpMock.expectOne({ method: 'PUT' }); + req.flush(JSON.stringify(returnedFromService)); + }); + + it('should return a list of Station', async () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB' + }, + elemDefault + ); + const expected = Object.assign({}, returnedFromService); + service + .query(expected) + .pipe( + take(1), + map(resp => resp.body) + ) + .subscribe(body => expect(body).toContainEqual(expected)); + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(JSON.stringify([returnedFromService])); + httpMock.verify(); + }); + + it('should delete a Station', async () => { + const rxPromise = service.delete('123').subscribe(resp => expect(resp.ok)); + + const req = httpMock.expectOne({ method: 'DELETE' }); + req.flush({ status: 200 }); + }); + }); + + afterEach(() => { + httpMock.verify(); + }); + }); +}); diff --git a/virta.jh b/virta.jh new file mode 100644 index 0000000..26d1afd --- /dev/null +++ b/virta.jh @@ -0,0 +1,26 @@ +entity Company { + id String required + name String required +} + +entity Station { + id String required + name String required +} + +relationship ManyToOne { + Company{parent} to Company + Station{company} to Company +} + +// Set pagination options +paginate Company with pagination + +// Use Data Transfert Objects (DTO) +// dto * with mapstruct + +// Set service options to all except few +service all with serviceImpl except Employee, Job + +// Set an angular suffix +// angularSuffix * with mySuffix