/*
 *  Copyright 2012-2014 Eurocommercial Properties NV
 *
 *  Licensed under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.estatio.api;

import java.math.BigDecimal;
import java.util.List;
import javax.inject.Inject;
import org.apache.isis.applib.AbstractFactoryAndRepository;
import org.apache.isis.applib.annotation.*;
import org.apache.isis.applib.annotation.ActionSemantics.Of;
import org.estatio.dom.asset.Properties;
import org.estatio.dom.asset.Unit;
import org.estatio.dom.asset.Units;
import org.estatio.dom.asset.registration.FixedAssetRegistration;
import org.estatio.dom.asset.registration.FixedAssetRegistrationTypes;
import org.estatio.dom.asset.registration.FixedAssetRegistrations;
import org.estatio.dom.asset.registration.LandRegister;

public class ApiItaly extends AbstractFactoryAndRepository {

    @Override
    public String getId() {
        return "apiItaly";
    }

    public String iconName() {
        return "Api";
    }

    // //////////////////////////////////////

    @MemberOrder(name="Migration", sequence = "90")
    @ActionSemantics(Of.IDEMPOTENT)
    public void putLandRegister(
            final @Named("propertyReference") String propertyReference,
            final @Named("unitReference") String unitReference,
            final @Named("comuneAmministrativo") @Optional String comuneAmministrativo,
            final @Named("comuneCatastale") @Optional String comuneCatastale,
            final @Named("codiceComuneCatastale") @Optional String codiceComuneCatastale,
            final @Named("rendita") @Optional BigDecimal rendita,
            final @Named("foglio") @Optional String foglio,
            final @Named("particella") @Optional String particella,
            final @Named("subalterno") @Optional String subalterno,
            final @Named("categoria") @Optional String categoria,
            final @Named("classe") @Optional String classe,
            final @Named("consistenza") @Optional String consistenza) {
        Unit unit = units.findUnitByReference(unitReference);
        LandRegister landRegister = null;
        List<FixedAssetRegistration> farts = fixedAssetRegistrations.findBySubject(unit);
        if (!farts.isEmpty()) {
            landRegister = (LandRegister) farts.get(0);
        }
        if (landRegister == null) {
            landRegister = (LandRegister) fixedAssetRegistrationTypes.findByTitle("LandRegister").create(getContainer());
            landRegister.setSubject(unit);
            landRegister.setComuneAmministrativo(comuneAmministrativo);
            landRegister.setComuneCatastale(codiceComuneCatastale);
            landRegister.setCodiceComuneCatastale(codiceComuneCatastale);
            landRegister.setRendita(rendita);
            landRegister.setFoglio(foglio);
            landRegister.setParticella(particella);
            landRegister.setSubalterno(subalterno);
            landRegister.setCategoria(categoria);
            landRegister.setClasse(classe);
            landRegister.setConsistenza(consistenza);
            persistIfNotAlready(landRegister);
        }
    }

    // //////////////////////////////////////

    @Inject
    private Properties properties;

    @Inject
    private Units<Unit> units;

    @Inject
    private FixedAssetRegistrations fixedAssetRegistrations;

    @Inject
    private FixedAssetRegistrationTypes fixedAssetRegistrationTypes;

}

@@ -699,252 +699,79 @@
 ava.
-util.List;%0Aimport javax.inject.Inject;%0Aimport org.apache.isis.applib.AbstractFactoryAndRepository;%0Aimport org.apache.isis.applib.annotation.*;%0Aimport org.apache.isis.applib.annotation.ActionSemantics.Of;%0Aimport org.estatio.dom.asset.Properties;
+math.RoundingMode;%0Aimport java.util.List;%0A%0Aimport javax.inject.Inject;%0A
 %0Aimp
@@ -1099,16 +1099,349 @@
 ister;%0A%0A
+import org.apache.isis.applib.AbstractFactoryAndRepository;%0Aimport org.apache.isis.applib.annotation.ActionSemantics;%0Aimport org.apache.isis.applib.annotation.ActionSemantics.Of;%0Aimport org.apache.isis.applib.annotation.MemberOrder;%0Aimport org.apache.isis.applib.annotation.Named;%0Aimport org.apache.isis.applib.annotation.Optional;%0A%0A
 public c
@@ -1698,17 +1698,19 @@
 der(name
-=
+ = 
 %22Migrati
@@ -2710,24 +2710,267 @@
 Reference);%0A
+        if (unit == null) %7B%0A            unit = units.findUnitByReference(unitReference.replace(%22 %22, %22+%22));%0A        %7D%0A        if (unit == null) %7B%0A            throw new IllegalArgumentException(%22Unknown unit: %22.concat(unitReference));%0A        %7D%0A
         Land
@@ -3645,16 +3645,77 @@
 (rendita
+ == null ? null : rendita.setScale(2, RoundingMode.HALF_EVEN)
 );%0A     
@@ -4120,56 +4120,8 @@
 //%0A%0A
-    @Inject%0A    private Properties properties;%0A%0A
     

Fix truncation of plus sign in api and set scale of rendita