data.services.ValueRangeService.java Source code

Java tutorial

Introduction

Here is the source code for data.services.ValueRangeService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package data.services;

import data.dao.ValueRangeDao;
import data.entity.ValueRange;
import data.services.parent.PrimService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import support.StringAdapter;

/**
 *
 * @author bezdatiuzer
 */
@Service
@Transactional
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ValueRangeService extends PrimService {

    @Autowired
    private ValueRangeDao valueRangeDao;

    public void delete(Long valueRangeId) {
        ValueRange vr = valueRangeDao.find(valueRangeId);
        if (vr != null) {
            valueRangeDao.delete(vr);
        }
    }

    /*public void create(ValueRange vr) throws Exception {
    if (valueRangeDao.find(vr).isEmpty()) {
        if (validate(vr)) {
            valueRangeDao.save(vr);
        }
    } else {
        addError("   ");
    }
    }*/

    public ValueRange getParam(Object uid, Object valMin, Object valMax, Object amin, Object amax) {
        ValueRange vr = new ValueRange();
        vr.setUid(StringAdapter.getString(uid).trim());
        vr.setAmax(Long.valueOf(getZeroInNullAndTrim(amax).trim()));
        vr.setAmin(Long.valueOf(getZeroInNullAndTrim(amin).trim()));
        vr.setValueMax(Long.valueOf(getZeroInNullAndTrim(valMax).trim()));
        vr.setValueMin(Long.valueOf(getZeroInNullAndTrim(valMin).trim()));
        //validate(vr);
        return vr;
    }

    public void create(ValueRange vr) {
        ValueRange supvr = new ValueRange();
        supvr.setUid(vr.getUid().trim());
        supvr.setScene(vr.getScene());
        //String arr = "";

        if (validate(vr)) {
            /*for(ValueRange ovr:valueRangeDao.findBySceneUid(supvr)){
            //arr+=ovr.getUid().trim() + "; " + ovr.getScene().getSceneId();
            valueRangeDao.delete(ovr);
            }*/
            valueRangeDao.save(vr);
            //addError(vr.getUid() + " + " + vr.getScene().getSceneId());
        }
    }

    private static String getZeroInNullAndTrim(Object obj) {
        if (StringAdapter.getString(obj).trim().equals("")) {
            return "0";
        } else {
            return StringAdapter.getString(obj).trim();
        }

    }

}