You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by iamrupok <gi...@git.apache.org> on 2017/06/11 04:26:10 UTC

[GitHub] fineract pull request #364: adhocquery v-1.0

GitHub user iamrupok opened a pull request:

    https://github.com/apache/fineract/pull/364

    adhocquery v-1.0

    PR-ADHOCQUERY

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/iamrupok/fineract develop

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/fineract/pull/364.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #364
    
----
commit 7d8db6a0ef3934f8899ecd53441cefa65ee346f5
Author: Kasem <ia...@gmail.com>
Date:   2017-06-11T04:17:26Z

    adhocquery v-1.0

----


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

[GitHub] fineract pull request #364: adhocquery v-1.0

Posted by iamrupok <gi...@git.apache.org>.
Github user iamrupok closed the pull request at:

    https://github.com/apache/fineract/pull/364


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

[GitHub] fineract issue #364: adhocquery v-1.0

Posted by iamrupok <gi...@git.apache.org>.
Github user iamrupok commented on the issue:

    https://github.com/apache/fineract/pull/364
  
    created a new pull request
    #365
    
    On Mon, Jun 12, 2017 at 11:26 AM, Shaik Nazeer Hussain <
    notifications@github.com> wrote:
    
    > *@nazeer1100126* commented on this pull request.
    > ------------------------------
    >
    > In fineract-provider/src/main/java/org/apache/fineract/adhocquery/api/
    > AdHocApiResource.java
    > <https://github.com/apache/fineract/pull/364#discussion_r121310884>:
    >
    > > +    @GET
    > +    @Path("{adHocId}")
    > +    @Consumes({ MediaType.APPLICATION_JSON })
    > +    @Produces({ MediaType.APPLICATION_JSON })
    > +    public String retrieveAdHocQuery(@PathParam("adHocId") final Long adHocId, @Context final UriInfo uriInfo) {
    > +
    > +        this.context.authenticatedUser();
    > +
    > +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    > +
    > +        final AdHocData adhoc = this.adHocReadPlatformService.retrieveOne(adHocId);
    > +
    > +        return this.toApiJsonSerializer.serialize(settings, adhoc, this.RESPONSE_DATA_PARAMETERS);
    > +    }
    > +
    > +/*    *//**
    >
    > Please remove unused/commented code
    > ------------------------------
    >
    > In fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/
    > AdHocWritePlatformServiceJpaRepositoryImpl.java
    > <https://github.com/apache/fineract/pull/364#discussion_r121311952>:
    >
    > > +
    > +    private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) {
    > +        logger.error(dve.getMessage(), dve);
    > +    }
    > +
    > +    //@Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) })
    > +    @Transactional
    > +    @Override
    > +    public CommandProcessingResult updateAdHocQuery(final Long roleId, final JsonCommand command) {
    > +        try {
    > +            this.context.authenticatedUser();
    > +
    > +            this.adHocCommandFromApiJsonDeserializer.validateForUpdate(command.json());
    > +
    > +            final AdHoc adHoc = this.adHocRepository.findOne(roleId);
    > +            if (adHoc == null) { throw new RoleNotFoundException(roleId); }
    >
    > if adHoc is null you should throw AdHocNotFoundException not
    > RoleNotFoundException?
    > ------------------------------
    >
    > In fineract-provider/src/main/java/org/apache/fineract/commands/service/
    > CommandWrapperBuilder.java
    > <https://github.com/apache/fineract/pull/364#discussion_r121312046>:
    >
    > > @@ -2904,4 +2904,43 @@ public CommandWrapperBuilder deleteSmsCampaign(final Long resourceId) {
    >          this.href = "/smscampaigns/"+resourceId;
    >          return this;
    >      }
    > +	public CommandWrapperBuilder disableAdHoc(Long adHocId) {
    > +        this.actionName = "DISABLE";
    > +        this.entityName = "ADHOC";
    > +        this.entityId = adHocId;
    > +        this.href = "/adhoc/" + adHocId + "/disbales";
    >
    > make it disable. I believe it should be command parameter?
    > ------------------------------
    >
    > In fineract-provider/src/main/resources/sql/migrations/core_
    > db/V323__adhocquery.sql
    > <https://github.com/apache/fineract/pull/364#discussion_r121312141>:
    >
    > > @@ -0,0 +1,48 @@
    > +--
    >
    > Current migration number 327. So Your migration script number should 328
    >
    > —
    > You are receiving this because you authored the thread.
    > Reply to this email directly, view it on GitHub
    > <https://github.com/apache/fineract/pull/364#pullrequestreview-43348064>,
    > or mute the thread
    > <https://github.com/notifications/unsubscribe-auth/ALCNBxjQNJtNT3K0Nn8_Q5lXo1IZtU0Uks5sDMwKgaJpZM4N2SsC>
    > .
    >



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

[GitHub] fineract issue #364: adhocquery v-1.0

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on the issue:

    https://github.com/apache/fineract/pull/364
  
    @iamrupok close this PR


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

[GitHub] fineract pull request #364: adhocquery v-1.0

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/364#discussion_r121311952
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/AdHocWritePlatformServiceJpaRepositoryImpl.java ---
    @@ -0,0 +1,197 @@
    +/**
    + * 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.adhocquery.service;
    +
    +import java.util.Map;
    +
    +import org.apache.fineract.adhocquery.domain.AdHoc;
    +import org.apache.fineract.adhocquery.domain.AdHocRepository;
    +import org.apache.fineract.adhocquery.exception.AdHocNotFoundException;
    +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.useradministration.exception.RoleNotFoundException;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.cache.annotation.CacheEvict;
    +import org.springframework.cache.annotation.Caching;
    +import org.springframework.dao.DataIntegrityViolationException;
    +import org.springframework.stereotype.Service;
    +import org.springframework.transaction.annotation.Transactional;
    +
    +@Service
    +public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePlatformService {
    +
    +    private final static Logger logger = LoggerFactory.getLogger(AdHocWritePlatformServiceJpaRepositoryImpl.class);
    +    private final PlatformSecurityContext context;
    +    private final AdHocRepository adHocRepository;
    +    private final AdHocDataValidator adHocCommandFromApiJsonDeserializer;
    +   
    +
    +    @Autowired
    +    public AdHocWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AdHocRepository roleRepository,
    +             final AdHocDataValidator adHocCommandFromApiJsonDeserializer) {
    +        this.context = context;
    +        this.adHocRepository = roleRepository;
    +        this.adHocCommandFromApiJsonDeserializer = adHocCommandFromApiJsonDeserializer;
    +       
    +    }
    +
    +    @Transactional
    +    @Override
    +    public CommandProcessingResult createAdHocQuery(final JsonCommand command) {
    +
    +        try {
    +            this.context.authenticatedUser();
    +
    +            this.adHocCommandFromApiJsonDeserializer.validateForCreate(command.json());
    +
    +            final AdHoc entity = AdHoc.fromJson(command);
    +            this.adHocRepository.save(entity);
    +
    +            return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build();
    +        } catch (final DataIntegrityViolationException dve) {
    +            handleDataIntegrityIssues(command, dve);
    +            return new CommandProcessingResultBuilder() //
    +                    .withCommandId(command.commandId()) //
    +                    .build();
    +        }
    +    }
    +
    +    /*
    +     * Guaranteed to throw an exception no matter what the data integrity issue
    +     * is.
    +     */
    +    private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
    +
    +        final Throwable realCause = dve.getMostSpecificCause();
    +        if (realCause.getMessage().contains("unq_name")) {
    +
    +            final String name = command.stringValueOfParameterNamed("name");
    +            throw new PlatformDataIntegrityException("error.msg.role.duplicate.name", "Role with name `" + name + "` already exists",
    +                    "name", name);
    +        }
    +
    +        logAsErrorUnexpectedDataIntegrityException(dve);
    +        throw new PlatformDataIntegrityException("error.msg.role.unknown.data.integrity.issue",
    +                "Unknown data integrity issue with resource.");
    +    }
    +
    +    private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) {
    +        logger.error(dve.getMessage(), dve);
    +    }
    +
    +    //@Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) })
    +    @Transactional
    +    @Override
    +    public CommandProcessingResult updateAdHocQuery(final Long roleId, final JsonCommand command) {
    +        try {
    +            this.context.authenticatedUser();
    +
    +            this.adHocCommandFromApiJsonDeserializer.validateForUpdate(command.json());
    +
    +            final AdHoc adHoc = this.adHocRepository.findOne(roleId);
    +            if (adHoc == null) { throw new RoleNotFoundException(roleId); }
    --- End diff --
    
    if adHoc is  null you should throw AdHocNotFoundException  not RoleNotFoundException? 


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

[GitHub] fineract pull request #364: adhocquery v-1.0

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/364#discussion_r121312141
  
    --- Diff: fineract-provider/src/main/resources/sql/migrations/core_db/V323__adhocquery.sql ---
    @@ -0,0 +1,48 @@
    +--
    --- End diff --
    
    Current migration number 327. So Your migration script number should 328


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

[GitHub] fineract pull request #364: adhocquery v-1.0

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/364#discussion_r121310884
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/adhocquery/api/AdHocApiResource.java ---
    @@ -0,0 +1,200 @@
    +/**
    + * 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.adhocquery.api;
    +
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashSet;
    +import java.util.Set;
    +
    +import javax.ws.rs.Consumes;
    +import javax.ws.rs.DELETE;
    +import javax.ws.rs.GET;
    +import javax.ws.rs.POST;
    +import javax.ws.rs.PUT;
    +import javax.ws.rs.Path;
    +import javax.ws.rs.PathParam;
    +import javax.ws.rs.Produces;
    +import javax.ws.rs.core.Context;
    +import javax.ws.rs.core.MediaType;
    +import javax.ws.rs.core.UriInfo;
    +
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.fineract.adhocquery.data.AdHocData;
    +import org.apache.fineract.adhocquery.service.AdHocReadPlatformService;
    +import org.apache.fineract.commands.domain.CommandWrapper;
    +import org.apache.fineract.commands.service.CommandWrapperBuilder;
    +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
    +import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
    +import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
    +import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
    +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.context.annotation.Scope;
    +import org.springframework.stereotype.Component;
    +
    +@Path("/adhocquery")
    +@Component
    +@Scope("singleton")
    +public class AdHocApiResource {
    +
    +    /**
    +     * The set of parameters that are supported in response for {@link AdhocData}
    +     */ 
    +    private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "name", "query", "tableName","tableField","isActive","createdBy","createdOn","createdById","updatedById","updatedOn","email"));
    +    
    +    private final PlatformSecurityContext context;
    +    private final AdHocReadPlatformService adHocReadPlatformService;
    +    private final DefaultToApiJsonSerializer<AdHocData> toApiJsonSerializer;
    +    private final ApiRequestParameterHelper apiRequestParameterHelper;
    +    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
    +
    +    @Autowired
    +    public AdHocApiResource(final PlatformSecurityContext context, final AdHocReadPlatformService readPlatformService,
    +            final DefaultToApiJsonSerializer<AdHocData> toApiJsonSerializer,
    +            final ApiRequestParameterHelper apiRequestParameterHelper,
    +            final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
    +        this.context = context;
    +        this.adHocReadPlatformService = readPlatformService;
    +        this.toApiJsonSerializer = toApiJsonSerializer;
    +        this.apiRequestParameterHelper = apiRequestParameterHelper;
    +        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
    +    }
    +
    +    @GET
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String retrieveAll(@Context final UriInfo uriInfo) {
    +    	System.out.println("In get method");	
    +        this.context.authenticatedUser();
    +        final Collection<AdHocData> roles = this.adHocReadPlatformService.retrieveAllAdHocQuery();
    +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    +        return this.toApiJsonSerializer.serialize(settings, roles, this.RESPONSE_DATA_PARAMETERS);
    +    }
    +    @GET
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    @Path("template")
    +    public String template(@Context final UriInfo uriInfo) {
    +        this.context.authenticatedUser();
    +        final AdHocData user = this.adHocReadPlatformService.retrieveNewAdHocDetails();
    +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    +        return this.toApiJsonSerializer.serialize(settings, user, this.RESPONSE_DATA_PARAMETERS);
    +    }
    +    @POST
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String createAdHocQuery(final String apiRequestBodyAsJson) {
    +
    +        final CommandWrapper commandRequest = new CommandWrapperBuilder() //
    +                .createAdHoc() //
    +                .withJson(apiRequestBodyAsJson) //
    +                .build();
    +
    +        final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
    +
    +        return this.toApiJsonSerializer.serialize(result);
    +    }
    +
    +    @GET
    +    @Path("{adHocId}")
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String retrieveAdHocQuery(@PathParam("adHocId") final Long adHocId, @Context final UriInfo uriInfo) {
    +
    +        this.context.authenticatedUser();
    +
    +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    +
    +        final AdHocData adhoc = this.adHocReadPlatformService.retrieveOne(adHocId);
    +
    +        return this.toApiJsonSerializer.serialize(settings, adhoc, this.RESPONSE_DATA_PARAMETERS);
    +    }
    +
    +/*    *//**
    --- End diff --
    
    Please remove unused/commented code


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

[GitHub] fineract pull request #364: adhocquery v-1.0

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/364#discussion_r121312046
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java ---
    @@ -2904,4 +2904,43 @@ public CommandWrapperBuilder deleteSmsCampaign(final Long resourceId) {
             this.href = "/smscampaigns/"+resourceId;
             return this;
         }
    +	public CommandWrapperBuilder disableAdHoc(Long adHocId) {
    +        this.actionName = "DISABLE";
    +        this.entityName = "ADHOC";
    +        this.entityId = adHocId;
    +        this.href = "/adhoc/" + adHocId + "/disbales";
    --- End diff --
    
    make it disable. I believe it should be command parameter?


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