Package framework.beans.address.entities

Examples of framework.beans.address.entities.AddressObject


        Field[] f = new Field[1];
        f[0] = new Field("parent", null, Field.OPERATOR_IS_NULL);
        Iterator<AddressObject> it = findEntityList(AddressObject.class, f).iterator();
        ArrayList<AddressObjectDetails> list = new ArrayList<AddressObjectDetails>();
        while (it.hasNext()) {
            AddressObject object = it.next();
            list.add(object.getDetails(this));
        }
        return list;
    }
View Full Code Here


     * @throws ClipsServerException
     */
    @Override
    protected void set(AddressObject entity, AddressObjectDetails details) throws ClipsServerException {
        AddressObjectDetails d = details;
        AddressObject ao = entity;
        ao.setActual(false);
        ao.setIfnsCode(d.ifnsCode);
        ao.setIfnsLocalCode(d.ifnsLocalCode);
        ao.setOkato(d.okato);
        ao.setParent(d.parentItem == 0 ? null : findAddressObject(d.parentItem));
        if (d.parentItem != 0){//так обновляются дети
            //Бубен, т.к. поле кода уникальное
            Iterator it = findEntityWhat("a.kladrCode",
                                        AddressObject.class,
                                        new Field[]{new Field("actual", false),
                                                    new Field("parent", ao.getParent()),
                                                    new Field("kladrCode", "%.%", Field.OPERATOR_LIKE)},
                                        "").iterator();
            int c = 0;
            boolean hasChildren = false;
            while (it.hasNext()) {
                hasChildren = true;
                String s =(String)it.next();
                int c1 = Integer.parseInt(s.substring(s.lastIndexOf(".")+1));
                if (c1 > c){
                    c = c1;
                }
            }
            if (hasChildren){
                ao.setKladrCode(ao.getParent().getKladrCode() + "." + (c + 1));
            }else{
                ao.setKladrCode(ao.getParent().getKladrCode() + ".1");
            }
        }else{//так обновляются родители (страны)
            String code = ao.getKladrCode();
            ao.setKladrCode(d.kladrCode);
            List<AddressObject> addressObjects
                    = findEntityList(AddressObject.class,
                                    new Field[]{new Field("parent", null, Field.OPERATOR_NOT_NULL),
                                                new Field("actual", false),
                                                new Field("kladrCode", code + ".%", Field.OPERATOR_LIKE)});

            if (ao.getId() != AddressObject.ADDRESS_OBJECT_RUSSIA){
                for (AddressObject addressObject : addressObjects) {
                    String kladrCode = addressObject.getKladrCode();
                    int point = kladrCode.indexOf(".");
                    kladrCode = ao.getKladrCode() + kladrCode.substring(point);
                    addressObject.setKladrCode(kladrCode);
                }
            }

        }
        ao.setPostIndex(d.postIndex);
        ao.setTitle(d.title);
        //ao.setDirty(details.dirty);
        ao.setType(findAddressObjectType(d.typeId));
    }
View Full Code Here

        ao.setType(findAddressObjectType(d.typeId));
    }

    @Override
    public List<AddressObjectDetails> getItems(int parentId) throws ClipsServerException {
        AddressObject parent = findAddressObject(parentId);
        ArrayList<AddressObjectDetails> list = new ArrayList<AddressObjectDetails>();
        List<AddressObject> it = findEntityList(AddressObject.class, "parent", parent, "ORDER by a.id");
//        System.out.println("KLADR BEAN getItems for " + parent.getTitle());
        for (AddressObject addressObject : it) {
            System.out.println("          " + addressObject.getTitle());
View Full Code Here

        return list;
    }

    @Override
    public List<AddressObjectDetails> getPath(int itemId) throws ClipsServerException {
        AddressObject object = findAddressObject(itemId);
        ArrayList<AddressObjectDetails> list = new ArrayList<AddressObjectDetails>();
        while(object != null){
            list.add(0, object.getDetails(this));
            object = object.getParent();
        }
        return list;
    }
View Full Code Here

    public void syncDirectory(List<KladrItem> roots, Map<KladrCode, KladrCode> altnames) throws ClipsServerException {
//        toDelete = new HashSet<Integer>();
        Field[] f = new Field[]{new Field("kladrCode", altnames.values(), Field.OPERATOR_IN)};
        Iterator iterator = findEntityList(AddressObject.class, f).iterator();
        while (iterator.hasNext()) {
            AddressObject ao = (AddressObject)iterator.next();
            ao.setKladrCode(altnames.get(new KladrCode(ao.getKladrCode())).toString());
            ao.setActual(false);
            manager.merge(ao);
        }
        manager.flush();
        for (KladrItem root : roots) {
            syncRoot(root);
View Full Code Here

     */
    private void syncRoot(KladrItem root) throws ClipsServerException {

        System.out.println("DIRECTORYCLADRBEAN update region: " + root);
        AddressItem region = new AddressItem(root);
        AddressObject russia = findAddressObject(AddressObject.ADDRESS_OBJECT_RUSSIA);
        Field[] f = new Field[]{new Field("kladrCode", root.kladrCode.toString().substring(0, 2).toString()+"%", Field.OPERATOR_LIKE)/*,
                                new Field("kladrCode", nextCode, Field.OPERATOR_LESS)*/};
        Iterator iterator = findEntityList(AddressObject.class, f).iterator();

        System.out.println("DIRECTORYCLADRBEAN load from db");
        int num = 0;
        while (iterator.hasNext()) {
            num++;
            if (num % 1000 == 0){
                System.out.println("DIRECTORYCLADRBEAN process records: " + num);
            }
            AddressObject addressObject = (AddressObject) iterator.next();
            KladrCode code = new KladrCode(addressObject.getKladrCode());
            AddressItem item = region.getChlidByCode(code);
            if (item == null){
                if (code.equals(root.kladrCode)){
                    region.entity = addressObject;
                }else{
                //remove this entity
//                    toDelete.add(addressObject.getId());
                    addressObject.setActual(false);
                }
            }else{
                item.entity = addressObject;
            }
        }
        System.out.println("DIRECTORYCLADRBEAN loded records: " + num);

        System.out.println("DIRECTORYCLADRBEAN update");
        updateCount = 0;
        if (region.entity == null) {
            region.entity = new AddressObject();
        }
        region.changed = fillEntity(region, russia);
         if (region.changed){
            if (region.entity.getId() == 0){
                manager.persist(region.entity);
View Full Code Here

     * @throws generic.ClipsServerException
     */
    private void updateRecoursive(AddressItem item) throws ClipsServerException{
        for(AddressItem child : item.children){
            if (child.entity == null) {
                child.entity = new AddressObject();
            }

            child.changed = fillEntity(child, item.entity);

            if (child.changed){
                AddressObject addressObject = child.entity;
                if (addressObject.getId() == 0){
                    manager.persist(addressObject);
                }else{
                    child.entity = manager.merge(addressObject);
                }

View Full Code Here

     * Проверка на наличие циклических ссылок
     * @param object
     * @throws generic.ClipsServerException
     */
    public void checkCicrcle(AddressObject object) throws ClipsServerException{
        AddressObject current = object.getParent();
        while (current != null) {
            if (current.getKladrCode().equals(object.getKladrCode())){

                //
                ArrayList<String> items = new ArrayList<String>(0){

                    @Override
                    public String toString() {
                        String s = new String();
                        for (Object object1 : this) {
                            s+=object1;
                        }
                        return s;
                    }

                };
                items.add(object.toString());
                AddressObject current1 = object.getParent();
                while (current1 != null) {
                    if (current.getKladrCode().equals(object.getKladrCode())){
                        items.add(current1.toString());
                    }
                    current1 = current1.getParent();
                }
                throw  new ClipsServerException("Циклическая ссылка: " + items + ", замыкается на элементе: " + current);
            }
            current = current.getParent();
        }
View Full Code Here

     * @return обновленные детали
     * @throws ClipsServerException
     */
    @Override
    public AddressDetails correctDetails(AddressDetails details) throws ClipsServerException {
        AddressObject street = findEntity(AddressObject.class, details.objectId);
        //really street?
        if (street != null && street.getType().getLevel() > AddressObjectType.ADDRESS_OBJECT_LEVEL_STREET){//block
            //do nothing
        }else if (street != null && street.getType().getLevel() == AddressObjectType.ADDRESS_OBJECT_LEVEL_STREET){//street
            List<AddressObject> blocks = findEntityList(AddressObject.class, "parent", street, "ORDER by a.id");
            for (AddressObject block : blocks) {
                if (include(block, details.building)){
                    details.objectId = block.getId();
                    break;
View Full Code Here

        if(filter.pathron != null && !filter.pathron.isEmpty()) {
      fields.add(new Field("pathronymic.title", filter.pathron.replace("%", "") + "%", Field.OPERATOR_LIKE));
        }
        if (filter.ad != null && filter.ad.objectId != 0) {
            AddressDetails ad = filter.ad;
            AddressObject addressObject = findEntity(AddressObject.class, ad.objectId);
            int level = addressObject.getType().getLevel();
           
            if (addressObject.getId() == AddressObject.ADDRESS_OBJECT_RUSSIA){
        //у буржундии код начинается с минуса
        // TODO: выглядит очень странно, можте глюк?
        fields.add(new Field("address.addressObject.kladrCode", "-%", Field.OPERATOR_NOT_LIKE));
            }
      else{
        String    code = addressObject.getKladrCode();
        String    subcode;
        switch (level) {
          case 1:
            subcode = code.substring(0, 2);
            break;
View Full Code Here

TOP

Related Classes of framework.beans.address.entities.AddressObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.