Skip to content

Commit

Permalink
Issue #185: Implementazione delle FAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
cironepa committed Jul 23, 2019
1 parent 2670dfb commit cd2c948
Show file tree
Hide file tree
Showing 15 changed files with 582 additions and 4 deletions.
95 changes: 95 additions & 0 deletions src/main/java/it/cnr/si/domain/Faq.java
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 + "'" +
'}';
}
}
18 changes: 18 additions & 0 deletions src/main/java/it/cnr/si/repository/FaqRepository.java
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();
}
147 changes: 147 additions & 0 deletions src/main/java/it/cnr/si/web/rest/FaqResource.java
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();
}

}
1 change: 1 addition & 0 deletions src/main/resources/config/liquibase/cnr/base-faq.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id;testo;is_readable
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>
2 changes: 2 additions & 0 deletions src/main/resources/config/liquibase/cnr/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/cnr/changelog/20190320102314_added_entity_ExternalMessage.xml"
relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/cnr/changelog/20190723085228_added_entity_Faq.xml"
relativeToChangelogFile="false"/>

</databaseChangeLog>
4 changes: 4 additions & 0 deletions src/main/resources/config/liquibase/cnr/new/faq.csv
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
8 changes: 7 additions & 1 deletion src/main/webapp/app/layouts/navbar/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<li ng-if="app == 'cnr'" ui-sref-active="active" has-authority="ROLE_USER">
<a ui-sref="manualistica" ng-click="vm.collapseNavbar()">
<span class="glyphicon glyphicon-book"></span>
<span class="hidden-sm">Manualistica</span>
<span class="hidden-sm">Manualistica&Faq</span>
</a>
</li>
<!-- jhipster-needle-add-element-to-menu - JHipster will add new menu items here -->
Expand Down Expand Up @@ -199,6 +199,12 @@
<span translate="global.menu.entities.externalMessage">External Message</span>
</a>
</li>
<li ui-sref-active="active" >
<a ui-sref="faq" ng-click="vm.collapseNavbar()">
<span class="glyphicon glyphicon-asterisk"></span>&nbsp;
<span translate="global.menu.entities.faq">Faq</span>
</a>
</li>
<!-- jhipster-needle-add-entity-to-menu - JHipster will add entities to the menu here -->
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

function ManualisticaController($scope, $state, dataService, utils) {
var vm = this;

//Recupero i Manuali
dataService.manuali.getElenco().then(function(response) {
vm.manuali = response.data;
});
//Recupero le Faq readable
dataService.faq.getReadable().then(function(faqs) {
vm.faqs = faqs.data;
});

$scope.downloadManuale = function(manuale) {

Expand Down
9 changes: 7 additions & 2 deletions src/main/webapp/app/pages/manualistica/manualistica.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class="row">

<div class="col-sm-6 col-sm-offset-3">

<h3>Manualistica</h3>

<ul>
<!--<li><a href="https://doc-cnr.si.cnr.it/rest/content?nodeRef=e6765d0c-eca5-4503-93ca-b5dde27ea68a">Manuale utente Flusso Acquisti</a></li>-->
<li ng-repeat="manuale in vm.manuali">
Expand All @@ -15,6 +13,13 @@ <h3>Manualistica</h3>
<a href="https://e-learning.formazione.cnr.it/course/view.php?id=5">Video Tutorial</a>
</li>
</ul>
<h3>Faq</h3>
<ul>
<li ng-repeat="faq in vm.faqs">
{{faq.testo}}
</li>

</ul>

</div>

Expand Down
Loading

0 comments on commit cd2c948

Please sign in to comment.