Skip to content

Commit

Permalink
Added entities, services and resources for dependency tracking #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tillias committed Oct 5, 2020
1 parent 768bdee commit 11f06b9
Show file tree
Hide file tree
Showing 43 changed files with 1,799 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .jhipster/Dependency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "Dependency",
"fields": [
{
"fieldName": "name",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
},
{
"fieldName": "description",
"fieldType": "byte[]",
"fieldTypeBlobContent": "text"
}
],
"relationships": [
{
"relationshipType": "many-to-one",
"otherEntityName": "microservice",
"otherEntityRelationshipName": "dependency",
"relationshipValidateRules": "required",
"relationshipName": "source",
"otherEntityField": "id"
},
{
"relationshipType": "many-to-one",
"otherEntityName": "microservice",
"otherEntityRelationshipName": "dependency",
"relationshipValidateRules": "required",
"relationshipName": "target",
"otherEntityField": "id"
}
],
"changelogDate": "20201005051343",
"entityTableName": "dependency",
"dto": "no",
"pagination": "no",
"service": "no",
"jpaMetamodelFiltering": false,
"fluentMethods": true,
"readOnly": false,
"embedded": false,
"clientRootFolder": "",
"applications": "*"
}
7 changes: 7 additions & 0 deletions microcatalog.jdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ entity Microservice {
gitUrl String required
}

entity Dependency {
name String required
description TextBlob
}

relationship ManyToOne {
Microservice{team required} to Team
Microservice{status required} to Status
Dependency{source required} to Microservice
Dependency{target required} to Microservice
}

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public JCacheManagerCustomizer cacheManagerCustomizer() {
createCache(cm, com.github.microcatalog.domain.Microservice.class.getName());
createCache(cm, com.github.microcatalog.domain.Team.class.getName());
createCache(cm, com.github.microcatalog.domain.Status.class.getName());
createCache(cm, com.github.microcatalog.domain.Dependency.class.getName());
// jhipster-needle-ehcache-add-entry
};
}
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/com/github/microcatalog/domain/Dependency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.github.microcatalog.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import javax.validation.constraints.*;

import java.io.Serializable;

/**
* A Dependency.
*/
@Entity
@Table(name = "dependency")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Dependency implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;

@NotNull
@Column(name = "name", nullable = false)
private String name;

@Lob
@Type(type = "org.hibernate.type.TextType")
@Column(name = "description")
private String description;

@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties(value = "dependencies", allowSetters = true)
private Microservice source;

@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties(value = "dependencies", allowSetters = true)
private Microservice target;

// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public Dependency name(String name) {
this.name = name;
return this;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public Dependency description(String description) {
this.description = description;
return this;
}

public void setDescription(String description) {
this.description = description;
}

public Microservice getSource() {
return source;
}

public Dependency source(Microservice microservice) {
this.source = microservice;
return this;
}

public void setSource(Microservice microservice) {
this.source = microservice;
}

public Microservice getTarget() {
return target;
}

public Dependency target(Microservice microservice) {
this.target = microservice;
return this;
}

public void setTarget(Microservice microservice) {
this.target = microservice;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Dependency)) {
return false;
}
return id != null && id.equals(((Dependency) o).id);
}

@Override
public int hashCode() {
return 31;
}

// prettier-ignore
@Override
public String toString() {
return "Dependency{" +
"id=" + getId() +
", name='" + getName() + "'" +
", description='" + getDescription() + "'" +
"}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.microcatalog.repository;

import com.github.microcatalog.domain.Dependency;

import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

/**
* Spring Data repository for the Dependency entity.
*/
@SuppressWarnings("unused")
@Repository
public interface DependencyRepository extends JpaRepository<Dependency, Long> {
}
119 changes: 119 additions & 0 deletions src/main/java/com/github/microcatalog/web/rest/DependencyResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.github.microcatalog.web.rest;

import com.github.microcatalog.domain.Dependency;
import com.github.microcatalog.repository.DependencyRepository;
import com.github.microcatalog.web.rest.errors.BadRequestAlertException;

import io.github.jhipster.web.util.HeaderUtil;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
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 {@link com.github.microcatalog.domain.Dependency}.
*/
@RestController
@RequestMapping("/api")
@Transactional
public class DependencyResource {

private final Logger log = LoggerFactory.getLogger(DependencyResource.class);

private static final String ENTITY_NAME = "dependency";

@Value("${jhipster.clientApp.name}")
private String applicationName;

private final DependencyRepository dependencyRepository;

public DependencyResource(DependencyRepository dependencyRepository) {
this.dependencyRepository = dependencyRepository;
}

/**
* {@code POST /dependencies} : Create a new dependency.
*
* @param dependency the dependency to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new dependency, or with status {@code 400 (Bad Request)} if the dependency has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("/dependencies")
public ResponseEntity<Dependency> createDependency(@Valid @RequestBody Dependency dependency) throws URISyntaxException {
log.debug("REST request to save Dependency : {}", dependency);
if (dependency.getId() != null) {
throw new BadRequestAlertException("A new dependency cannot already have an ID", ENTITY_NAME, "idexists");
}
Dependency result = dependencyRepository.save(dependency);
return ResponseEntity.created(new URI("/api/dependencies/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString()))
.body(result);
}

/**
* {@code PUT /dependencies} : Updates an existing dependency.
*
* @param dependency the dependency to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated dependency,
* or with status {@code 400 (Bad Request)} if the dependency is not valid,
* or with status {@code 500 (Internal Server Error)} if the dependency couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/dependencies")
public ResponseEntity<Dependency> updateDependency(@Valid @RequestBody Dependency dependency) throws URISyntaxException {
log.debug("REST request to update Dependency : {}", dependency);
if (dependency.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
Dependency result = dependencyRepository.save(dependency);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, dependency.getId().toString()))
.body(result);
}

/**
* {@code GET /dependencies} : get all the dependencies.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of dependencies in body.
*/
@GetMapping("/dependencies")
public List<Dependency> getAllDependencies() {
log.debug("REST request to get all Dependencies");
return dependencyRepository.findAll();
}

/**
* {@code GET /dependencies/:id} : get the "id" dependency.
*
* @param id the id of the dependency to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the dependency, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/dependencies/{id}")
public ResponseEntity<Dependency> getDependency(@PathVariable Long id) {
log.debug("REST request to get Dependency : {}", id);
Optional<Dependency> dependency = dependencyRepository.findById(id);
return ResponseUtil.wrapOrNotFound(dependency);
}

/**
* {@code DELETE /dependencies/:id} : delete the "id" dependency.
*
* @param id the id of the dependency to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/dependencies/{id}")
public ResponseEntity<Void> deleteDependency(@PathVariable Long id) {
log.debug("REST request to delete Dependency : {}", id);
dependencyRepository.deleteById(id);
return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString())).build();
}
}
Loading

0 comments on commit 11f06b9

Please sign in to comment.