All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.faces.communication.CommunicationDataController Maven / Gradle / Ivy

package br.com.jarch.faces.communication;

import br.com.jarch.core.annotation.JArchDataController;
import br.com.jarch.core.crud.communication.CommunicationEntity;
import br.com.jarch.core.crud.communication.CommunicationRepository;
import br.com.jarch.core.crud.communication.CommunicationService;
import br.com.jarch.faces.controller.CrudDataController;
import br.com.jarch.faces.util.JavaScriptUtils;
import br.com.jarch.faces.util.MacAddressUtils;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.time.LocalDate;

@JArchDataController
public class CommunicationDataController extends CrudDataController {

    @PostConstruct
    public void init(){
        if (getEntity().getReading() == null) {
            getEntity().setOthers(MacAddressUtils.getIpAddr());
            getService().saveDataReading(getEntity());
        }
    }

    public void archived() {
        getService().archived(getEntity());

    	JavaScriptUtils.showMessageBodySuccessRedirect(getPageList());
    }

    @Override
    public String getPageList() {
        return "../login/bemVindo.jsf";
    }

    public void delete() {
        getService().delete(getEntity());
    }

    public StreamedContent download() {
        return DefaultStreamedContent
                .builder()
                .stream(() -> new ByteArrayInputStream(getEntity().getBinary()))
                .name(getEntity().getFileName())
                .build();
    }

    public LocalDate getExpiration() {
        return entity.getExpiration();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy