-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #185: Implementazione delle FAQ
- Loading branch information
Showing
15 changed files
with
582 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package it.cnr.si.domain; | ||
|
||
import org.hibernate.annotations.Cache; | ||
import org.hibernate.annotations.CacheConcurrencyStrategy; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A Faq. | ||
*/ | ||
@Entity | ||
@Table(name = "faq") | ||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | ||
public class Faq implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@NotNull | ||
@Column(name = "testo", nullable = false) | ||
private String testo; | ||
|
||
@NotNull | ||
@Column(name = "is_readable", nullable = false) | ||
private Boolean isReadable; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTesto() { | ||
return testo; | ||
} | ||
|
||
public Faq testo(String testo) { | ||
this.testo = testo; | ||
return this; | ||
} | ||
|
||
public void setTesto(String testo) { | ||
this.testo = testo; | ||
} | ||
|
||
public Boolean isIsReadable() { | ||
return isReadable; | ||
} | ||
|
||
public Faq isReadable(Boolean isReadable) { | ||
this.isReadable = isReadable; | ||
return this; | ||
} | ||
|
||
public void setIsReadable(Boolean isReadable) { | ||
this.isReadable = isReadable; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Faq faq = (Faq) o; | ||
if(faq.id == null || id == null) { | ||
return false; | ||
} | ||
return Objects.equals(id, faq.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Faq{" + | ||
"id=" + id + | ||
", testo='" + testo + "'" + | ||
", isReadable='" + isReadable + "'" + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.cnr.si.repository; | ||
|
||
import it.cnr.si.domain.Faq; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Spring Data JPA repository for the Faq entity. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public interface FaqRepository extends JpaRepository<Faq,Long> { | ||
|
||
|
||
@Query("select faq from Faq faq where faq.isReadable = TRUE") | ||
public List<Faq> getReadableFaq(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package it.cnr.si.web.rest; | ||
|
||
import com.codahale.metrics.annotation.Timed; | ||
import it.cnr.si.domain.Faq; | ||
import it.cnr.si.repository.FaqRepository; | ||
import it.cnr.si.web.rest.util.HeaderUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.inject.Inject; | ||
import javax.validation.Valid; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* REST controller for managing Faq. | ||
*/ | ||
@RestController | ||
@RequestMapping("/api") | ||
public class FaqResource { | ||
|
||
private final Logger log = LoggerFactory.getLogger(FaqResource.class); | ||
|
||
@Inject | ||
private FaqRepository faqRepository; | ||
|
||
/** | ||
* POST /faqs : Create a new faq. | ||
* | ||
* @param faq the faq to create | ||
* @return the ResponseEntity with status 201 (Created) and with body the new faq, or with status 400 (Bad Request) if the faq has already an ID | ||
* @throws URISyntaxException if the Location URI syntax is incorrect | ||
*/ | ||
@RequestMapping(value = "/faqs", | ||
method = RequestMethod.POST, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public ResponseEntity<Faq> createFaq(@Valid @RequestBody Faq faq) throws URISyntaxException { | ||
log.debug("REST request to save Faq : {}", faq); | ||
if (faq.getId() != null) { | ||
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("faq", "idexists", "A new faq cannot already have an ID")).body(null); | ||
} | ||
Faq result = faqRepository.save(faq); | ||
return ResponseEntity.created(new URI("/api/faqs/" + result.getId())) | ||
.headers(HeaderUtil.createEntityCreationAlert("faq", result.getId().toString())) | ||
.body(result); | ||
} | ||
|
||
/** | ||
* PUT /faqs : Updates an existing faq. | ||
* | ||
* @param faq the faq to update | ||
* @return the ResponseEntity with status 200 (OK) and with body the updated faq, | ||
* or with status 400 (Bad Request) if the faq is not valid, | ||
* or with status 500 (Internal Server Error) if the faq couldnt be updated | ||
* @throws URISyntaxException if the Location URI syntax is incorrect | ||
*/ | ||
@RequestMapping(value = "/faqs", | ||
method = RequestMethod.PUT, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public ResponseEntity<Faq> updateFaq(@Valid @RequestBody Faq faq) throws URISyntaxException { | ||
log.debug("REST request to update Faq : {}", faq); | ||
if (faq.getId() == null) { | ||
return createFaq(faq); | ||
} | ||
Faq result = faqRepository.save(faq); | ||
return ResponseEntity.ok() | ||
.headers(HeaderUtil.createEntityUpdateAlert("faq", faq.getId().toString())) | ||
.body(result); | ||
} | ||
|
||
/** | ||
* GET /faqs : get all the faqs. | ||
* | ||
* @return the ResponseEntity with status 200 (OK) and the list of faqs in body | ||
*/ | ||
@RequestMapping(value = "/faqs", | ||
method = RequestMethod.GET, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public List<Faq> getAllFaqs() { | ||
log.debug("REST request to get all Faqs"); | ||
List<Faq> faqs = faqRepository.findAll(); | ||
return faqs; | ||
} | ||
|
||
|
||
|
||
/** | ||
* GET /activeFaqs : get all readable faqs. | ||
* | ||
* @return the ResponseEntity with status 200 (OK) and the list of faqs readable in body | ||
*/ | ||
@RequestMapping(value = "/faqs/readable", | ||
method = RequestMethod.GET, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public List<Faq> getReadableFaqs() { | ||
log.debug("REST request to get all Faqs"); | ||
List<Faq> faqs = faqRepository.getReadableFaq(); | ||
return faqs; | ||
} | ||
|
||
/** | ||
* GET /faqs/:id : get the "id" faq. | ||
* | ||
* @param id the id of the faq to retrieve | ||
* @return the ResponseEntity with status 200 (OK) and with body the faq, or with status 404 (Not Found) | ||
*/ | ||
@RequestMapping(value = "/faqs/{id}", | ||
method = RequestMethod.GET, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public ResponseEntity<Faq> getFaq(@PathVariable Long id) { | ||
log.debug("REST request to get Faq : {}", id); | ||
Faq faq = faqRepository.findOne(id); | ||
return Optional.ofNullable(faq) | ||
.map(result -> new ResponseEntity<>( | ||
result, | ||
HttpStatus.OK)) | ||
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); | ||
} | ||
|
||
/** | ||
* DELETE /faqs/:id : delete the "id" faq. | ||
* | ||
* @param id the id of the faq to delete | ||
* @return the ResponseEntity with status 200 (OK) | ||
*/ | ||
@RequestMapping(value = "/faqs/{id}", | ||
method = RequestMethod.DELETE, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Timed | ||
public ResponseEntity<Void> deleteFaq(@PathVariable Long id) { | ||
log.debug("REST request to delete Faq : {}", id); | ||
faqRepository.delete(id); | ||
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert("faq", id.toString())).build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id;testo;is_readable |
56 changes: 56 additions & 0 deletions
56
src/main/resources/config/liquibase/cnr/changelog/20190723085228_added_entity_Faq.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> | ||
|
||
<property name="now" value="now()" dbms="mysql,h2"/> | ||
<property name="now" value="current_timestamp" dbms="postgresql"/> | ||
<property name="now" value="sysdate" dbms="oracle"/> | ||
|
||
<property name="autoIncrement" value="true" dbms="mysql,h2,postgresql,oracle"/> | ||
|
||
<property name="floatType" value="float4" dbms="postgresql, h2"/> | ||
<property name="floatType" value="float" dbms="mysql, oracle"/> | ||
|
||
<!-- | ||
Added the entity Faq. | ||
--> | ||
<changeSet id="20190723085228-1" author="jhipster"> | ||
<createTable tableName="faq"> | ||
<column name="id" type="bigint" autoIncrement="${autoIncrement}"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
<column name="testo" type="varchar(255)"> | ||
<constraints nullable="false" /> | ||
</column> | ||
|
||
<column name="is_readable" type="BOOLEAN"> | ||
<constraints nullable="false" /> | ||
</column> | ||
|
||
<!-- jhipster-needle-liquibase-add-column - Jhipster will add columns here, do not remove--> | ||
</createTable> | ||
|
||
<loadData encoding="UTF-8" | ||
file="config/liquibase/cnr/base-faq.csv" | ||
separator=";" | ||
tableName="membership"/> | ||
|
||
</changeSet> | ||
|
||
<!--Vengono sovrascritte le tuple con lo stesso id nei csv nella cartella "modified"--> | ||
<!--non occorre eseguire il clear check sum ma basta un maven clean--> | ||
<changeSet id="20180410115515-2" author="Paolo" runOnChange='true'> | ||
<loadUpdateData encoding="UTF-8" | ||
file="config/liquibase/cnr/new/faq.csv" | ||
primaryKey="id" | ||
schemaName="public" | ||
separator=";" | ||
tableName="faq"> | ||
<column name="id" type="numeric"/> | ||
<column name="testo" type="string"/> | ||
<column name="is_readable" type="BOOLEAN"/> | ||
</loadUpdateData> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id;testo;is_readable | ||
1;Prova FAQ 1;TRUE | ||
2;Prova FAQ 2;TRUE | ||
3;Prova FAQ non leggibile;FALSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.