fineract-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nikpawar89 <...@git.apache.org>
Subject [GitHub] incubator-fineract pull request #189: address_module
Date Mon, 01 Aug 2016 13:14:59 GMT
Github user nikpawar89 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/189#discussion_r72975283
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
---
    @@ -0,0 +1,317 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements. See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership. The ASF licenses this file
    + * to you 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.apache.fineract.portfolio.address.service;
    +
    +import java.math.BigDecimal;
    +
    +import org.apache.fineract.infrastructure.codes.domain.CodeValue;
    +import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
    +import org.apache.fineract.infrastructure.core.api.JsonCommand;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
    +import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
    +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
    +import org.apache.fineract.portfolio.address.domain.Address;
    +import org.apache.fineract.portfolio.address.domain.AddressRepository;
    +import org.apache.fineract.portfolio.address.serialization.AddAddressCommandFromApiJsonDeserializer;
    +import org.apache.fineract.portfolio.client.domain.Client;
    +import org.apache.fineract.portfolio.client.domain.ClientAddress;
    +import org.apache.fineract.portfolio.client.domain.ClientAddressRepository;
    +import org.apache.fineract.portfolio.client.domain.ClientAddressRepositoryWrapper;
    +import org.apache.fineract.portfolio.client.domain.ClientRepository;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +import com.google.gson.JsonArray;
    +import com.google.gson.JsonObject;
    +
    +@Service
    +public class AddressWritePlatformServiceImpl implements AddressWritePlatformService {
    +	private final PlatformSecurityContext context;
    +	private final CodeValueRepository codeValueRepository;
    +	private final ClientAddressRepository clientAddressRepository;
    +	private final ClientRepository clientRepository;
    +	private final AddressRepository addressRepository;
    +	private final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper;
    +	private final AddAddressCommandFromApiJsonDeserializer fromApiJsonDeserializer;
    +	private final static Logger logger = LoggerFactory.getLogger(AddressWritePlatformServiceImpl.class);
    +
    +	@Autowired
    +	public AddressWritePlatformServiceImpl(final PlatformSecurityContext context,
    +			final CodeValueRepository codeValueRepository, final ClientAddressRepository clientAddressRepository,
    +			final ClientRepository clientRepository, final AddressRepository addressRepository,
    +			final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper,
    +			final AddAddressCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
    +		this.context = context;
    +		this.codeValueRepository = codeValueRepository;
    +		this.clientAddressRepository = clientAddressRepository;
    +		this.clientRepository = clientRepository;
    +		this.addressRepository = addressRepository;
    +		this.clientAddressRepositoryWrapper = clientAddressRepositoryWrapper;
    +		this.fromApiJsonDeserializer = fromApiJsonDeserializer;
    +	}
    +
    +	@Override
    +	public CommandProcessingResult addClientAddress(final Long clientId, final Long addressTypeId,
    +			final JsonCommand command) {
    +		CodeValue stateIdobj = null;
    +		CodeValue countryIdObj = null;
    +		long stateId;
    +		long countryId;
    +
    +		this.context.authenticatedUser();
    +		this.fromApiJsonDeserializer.validateForCreate(command.json(), false);
    +
    +		if (command.longValueOfParameterNamed("state_province_id") != null) {
    +			stateId = command.longValueOfParameterNamed("state_province_id");
    +			stateIdobj = this.codeValueRepository.getOne(stateId);
    +		}
    +
    +		if (command.longValueOfParameterNamed("country_id") != null) {
    +			countryId = command.longValueOfParameterNamed("country_id");
    +			countryIdObj = this.codeValueRepository.getOne(countryId);
    +		}
    +
    +		final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId);
    +
    +		final Address add = Address.fromJson(command, stateIdobj, countryIdObj);
    +		this.addressRepository.save(add);
    +		final Long addressid = add.getId();
    +		final Address addobj = this.addressRepository.getOne(addressid);
    +
    +		final Client client = this.clientRepository.getOne(clientId);
    +
    +		final ClientAddress clientAddressobj = ClientAddress.fromJson(command, client, addobj,
addressTypeIdObj);
    +		this.clientAddressRepository.save(clientAddressobj);
    +
    +		return new CommandProcessingResultBuilder().withCommandId(command.commandId())
    +				.withEntityId(clientAddressobj.getId()).build();
    +	}
    +
    +	@Override
    +	public CommandProcessingResult addNewClientAddress(final Client client, final JsonCommand
command) {
    +		CodeValue stateIdobj = null;
    +		CodeValue countryIdObj = null;
    +		long stateId;
    +		long countryId;
    +
    +		final JsonArray addressArray = command.arrayOfParameterNamed("address");
    +
    +		for (int i = 0; i < addressArray.size(); i++) {
    +			final JsonObject jsonObject = addressArray.get(i).getAsJsonObject();
    +			this.fromApiJsonDeserializer.validateForCreate(jsonObject.toString(), true);
    +
    +			if (command.longValueOfParameterNamed("state_province_id") != null) {
    +				stateId = command.longValueOfParameterNamed("state_province_id");
    +				stateIdobj = this.codeValueRepository.getOne(stateId);
    +			}
    +
    +			if (command.longValueOfParameterNamed("country_id") != null) {
    +				countryId = command.longValueOfParameterNamed("country_id");
    +				countryIdObj = this.codeValueRepository.getOne(countryId);
    +			}
    +
    +			final long addressTypeId = jsonObject.get("addressTypeId").getAsLong();
    +			final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId);
    +
    +			final Address add = Address.fromJsonObject(jsonObject, stateIdobj, countryIdObj);
    +			this.addressRepository.save(add);
    +			final Long addressid = add.getId();
    +			final Address addobj = this.addressRepository.getOne(addressid);
    +
    +			final ClientAddress clientAddressobj = ClientAddress.fromJson(command, client, addobj,
addressTypeIdObj);
    +			this.clientAddressRepository.save(clientAddressobj);
    +
    +		}
    +		final long typ = 1;
    +		return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(typ).build();
    +	}
    +
    +	@Override
    +	public CommandProcessingResult updateClientAddress(final Long clientId, final Long addressTypeId,
    +			final Boolean status, final JsonCommand command) {
    +		this.context.authenticatedUser();
    +
    +		long stateId;
    +
    +		long countryId;
    +
    +		CodeValue stateIdobj;
    +
    +		CodeValue countryIdObj;
    +
    +		boolean is_address_update = false;
    +
    +		boolean is_address_config_update = false;
    +
    +		final CodeValue addresstyp = this.codeValueRepository.getOne(addressTypeId);
    +		
    +		
    +		System.out.println("clientId is"+ clientId);
    +		System.out.println("addresstyp:" +addresstyp);
    +		System.out.println("status:" +status);
    +
    +		final ClientAddress clientAddressObj = this.clientAddressRepositoryWrapper
    +				.findOneByClientIdAndAddressTypeAndIsActive(clientId, addresstyp, status);
    +		System.out.println(clientAddressObj);
    --- End diff --
    
    done


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message