fineract-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100126 <...@git.apache.org>
Subject [GitHub] incubator-fineract pull request #202: address_module
Date Thu, 11 Aug 2016 05:46:42 GMT
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/202#discussion_r74370875
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
---
    @@ -0,0 +1,279 @@
    +/**
    + * 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.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.AddressCommandFromApiJsonDeserializer;
    +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.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 AddressCommandFromApiJsonDeserializer fromApiJsonDeserializer;
    +
    +	@Autowired
    +	public AddressWritePlatformServiceImpl(final PlatformSecurityContext context,
    +			final CodeValueRepository codeValueRepository, final ClientAddressRepository clientAddressRepository,
    +			final ClientRepository clientRepository, final AddressRepository addressRepository,
    +			final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper,
    +			final AddressCommandFromApiJsonDeserializer 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(), true);
    +		
    +		System.out.println("request "+command.json());
    +
    +		if (command.longValueOfParameterNamed("stateProvinceId") != null) {
    +			stateId = command.longValueOfParameterNamed("stateProvinceId");
    +			stateIdobj = this.codeValueRepository.getOne(stateId);
    +		}
    +
    +		if (command.longValueOfParameterNamed("countryId") != null) {
    +			countryId = command.longValueOfParameterNamed("countryId");
    +			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 boolean isActive = command.booleanPrimitiveValueOfParameterNamed("isActive");
    +
    +		final ClientAddress clientAddressobj = ClientAddress.fromJson(isActive, client, addobj,
addressTypeIdObj);
    +		this.clientAddressRepository.save(clientAddressobj);
    +
    +		return new CommandProcessingResultBuilder().withCommandId(command.commandId())
    +				.withEntityId(clientAddressobj.getId()).build();
    +	}
    +
    +	// following method is used for adding multiple addresses while creating new
    +	// client
    +
    +	@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();
    +
    +			// validate every address
    +			this.fromApiJsonDeserializer.validateForCreate(jsonObject.toString(), true);
    +
    +			if (jsonObject.get("stateProvinceId") != null) {
    +				stateId = jsonObject.get("stateProvinceId").getAsLong();
    +				stateIdobj = this.codeValueRepository.getOne(stateId);
    +			}
    +
    +			if (jsonObject.get("countryId") != null) {
    +				countryId = jsonObject.get("countryId").getAsLong();
    +				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 boolean isActive = jsonObject.get("isActive").getAsBoolean();
    +
    +			final ClientAddress clientAddressobj = ClientAddress.fromJson(isActive, 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 JsonCommand
command) {
    +		this.context.authenticatedUser();
    +
    +		long stateId;
    +
    +		long countryId;
    +
    +		CodeValue stateIdobj;
    +
    +		CodeValue countryIdObj;
    +
    +		boolean is_address_update = false;
    +
    +		this.fromApiJsonDeserializer.validateForUpdate(command.json());
    +
    +		final long addressId = command.longValueOfParameterNamed("addressId");
    +
    +		final ClientAddress clientAddressObj = this.clientAddressRepositoryWrapper
    +				.findOneByClientIdAndAddressId(clientId, addressId);
    +
    +		final Address addobj = this.addressRepository.getOne(addressId);
    +
    +		if (!(command.stringValueOfParameterNamed("street").isEmpty())) {
    --- End diff --
    
    If street is not passed in json, NullPointerException will thrown. This is same for all
parameters in update json.


---
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