Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/fineract/pull/401#discussion_r132181329
  
    --- Diff: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java
 ---
    @@ -0,0 +1,108 @@
    +/**
    + * 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.infrastructure.bulkimport.service;
    +
    +import java.io.ByteArrayOutputStream;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import javax.ws.rs.core.Response;
    +import javax.ws.rs.core.Response.ResponseBuilder;
    +
    +import 
org.apache.fineract.infrastructure.bulkimport.populator.WorkbookPopulator;
    +import 
org.apache.fineract.infrastructure.bulkimport.populator.office.OfficeWorkbookPopulator;
    +import 
org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
    +import org.apache.fineract.infrastructure.core.service.DateUtils;
    +import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
    +import org.apache.fineract.organisation.office.api.OfficeApiConstants;
    +import org.apache.fineract.organisation.office.data.OfficeData;
    +import 
org.apache.fineract.organisation.office.service.OfficeReadPlatformService;
    +
    +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    +import org.apache.poi.ss.usermodel.Workbook;
    +
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +@Service
    +public class BulkImportWorkbookPopulatorServiceImpl implements 
BulkImportWorkbookPopulatorService {
    +
    +   private final PlatformSecurityContext context;
    +   private final OfficeReadPlatformService officeReadPlatformService;
    +
    +   @Autowired
    +   public BulkImportWorkbookPopulatorServiceImpl(final 
PlatformSecurityContext context,
    +                   final OfficeReadPlatformService 
officeReadPlatformService) {
    +           this.context = context;
    +           this.officeReadPlatformService = officeReadPlatformService;
    +   }
    +
    +   @Override
    +   public Response getTemplate(final String entityType, final Long 
officeId, final Long staffId,final Long centerId,
    +                   final Long clientId,final Long groupId, final Long 
productId,final Long fundId,
    +                   final Long paymentTypeId,final String code,final Long 
glAccountId) {
    +
    +           WorkbookPopulator populator = null;
    +           final Workbook workbook = new HSSFWorkbook();
    +           if 
(entityType.trim().equalsIgnoreCase(OfficeApiConstants.OFFICE_RESOURCE_NAME)) {
    +                   populator = populateOfficeWorkbook(officeId);
    +           } else
    +                   throw new 
GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource",
    +                                   "Unable to find requested resource");
    +           populator.populate(workbook);
    +           return buildResponse(workbook, entityType);
    +   }
    +   private WorkbookPopulator populateOfficeWorkbook(Long officeId) {
    +           
this.context.authenticatedUser().validateHasReadPermission("OFFICE");
    +           List<OfficeData> offices = fetchOffices(officeId);
    +           return new OfficeWorkbookPopulator(offices);
    +   }
    +
    +   private Response buildResponse(final Workbook workbook, final String 
entity) {
    +           String filename = entity + 
DateUtils.getLocalDateOfTenant().toString() + ".xls";
    +           final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    +           try {
    +                   workbook.write(baos);
    +           } catch (IOException e) {
    +                   e.printStackTrace();
    +           }
    +
    +           final ResponseBuilder response = 
Response.ok(baos.toByteArray());
    +           response.header("Content-Disposition", "attachment; 
filename=\"" + filename + "\"");
    +           response.header("Content-Type", "application/vnd.ms-excel");
    +           return response.build();
    +   }
    +
    +   @SuppressWarnings("unchecked")
    +   private List<OfficeData> fetchOffices(final Long officeId) {
    +           List<OfficeData> offices = null;
    +           if (officeId == null) {
    +                   Boolean includeAllOffices = Boolean.TRUE;
    +                   offices = (List) 
this.officeReadPlatformService.retrieveAllOffices(includeAllOffices, null);
    +                   // System.out.println("Offices List size : 
"+offices.size());
    --- End diff --
    
    remove 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to