review changes to yanna pull request for mix-xbrl GSOC project.
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('xbrlmapping', 'UPDATE_XBRLMAPPING', 'XBRLMAPPING', 'UPDATE', 0);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES
|
||||
('xbrlmapping', 'UPDATE_XBRLMAPPING', 'XBRLMAPPING', 'UPDATE', 0);
|
||||
|
||||
DROP TABLE IF EXISTS `mix_taxonomy`;
|
||||
|
||||
CREATE TABLE `mix_taxonomy` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`name` varchar(100) DEFAULT NULL,
|
||||
`namespace_id` int(11) DEFAULT NULL,
|
||||
`dimension` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`dimension` varchar(100) DEFAULT NULL,
|
||||
`type` int(11) DEFAULT NULL,
|
||||
`description` varchar(1000) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`description` varchar(1000) DEFAULT NULL,
|
||||
`need_mapping` tinyint(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@@ -73,18 +74,17 @@ DROP TABLE IF EXISTS `mix_taxonomy_mapping`;
|
||||
|
||||
CREATE TABLE `mix_taxonomy_mapping` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(50) CHARACTER SET latin1 NOT NULL DEFAULT '',
|
||||
`config` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`identifier` varchar(50) NOT NULL DEFAULT '',
|
||||
`config` varchar(200) DEFAULT NULL,
|
||||
`last_update_date` datetime DEFAULT NULL,
|
||||
`currency` varchar(11) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`currency` varchar(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
LOCK TABLES `mix_taxonomy_mapping` WRITE;
|
||||
|
||||
INSERT INTO `mix_taxonomy_mapping` (`id`, `identifier`, `config`, `last_update_date`, `currency`)
|
||||
VALUES
|
||||
(1,'default',NULL,NULL,'');
|
||||
INSERT INTO `mix_taxonomy_mapping` (`id`, `identifier`, `config`, `last_update_date`, `currency`) VALUES
|
||||
(1,'default',NULL,NULL,'');
|
||||
|
||||
UNLOCK TABLES;
|
||||
|
||||
@@ -93,8 +93,8 @@ DROP TABLE IF EXISTS `mix_xbrl_namespace`;
|
||||
|
||||
CREATE TABLE `mix_xbrl_namespace` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`prefix` varchar(20) CHARACTER SET latin1 NOT NULL DEFAULT '',
|
||||
`url` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
|
||||
`prefix` varchar(20) NOT NULL DEFAULT '',
|
||||
`url` varchar(100) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `UNQUE` (`prefix`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@@ -110,5 +110,4 @@ VALUES
|
||||
(5,'xbrli','http://www.xbrl.org/2003/instance'),
|
||||
(6,'link','http://www.xbrl.org/2003/linkbase'),
|
||||
(7,'dc-all','http://www.themix.org/int/fr/ifrs/basi/2010-08-31/dc-all');
|
||||
|
||||
UNLOCK TABLES;
|
||||
UNLOCK TABLES;
|
||||
+11
-15
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.api;
|
||||
package org.mifosplatform.mix.api;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
@@ -8,9 +8,9 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.xbrl.report.service.XBRLBuilder;
|
||||
import org.mifosplatform.xbrl.report.service.XBRLResultService;
|
||||
import org.mifosplatform.mix.data.XBRLData;
|
||||
import org.mifosplatform.mix.service.XBRLBuilder;
|
||||
import org.mifosplatform.mix.service.XBRLResultService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -18,17 +18,15 @@ import org.springframework.stereotype.Component;
|
||||
@Path("/mixreport")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class XBRLReportApiResource {
|
||||
public class MixReportApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final XBRLResultService xbrlResultService;
|
||||
@Autowired
|
||||
private XBRLBuilder xbrlBuilder;
|
||||
private final XBRLBuilder xbrlBuilder;
|
||||
|
||||
@Autowired
|
||||
public XBRLReportApiResource(final PlatformSecurityContext context, final XBRLResultService xbrlResultService) {
|
||||
this.context = context;
|
||||
public MixReportApiResource(final XBRLResultService xbrlResultService, final XBRLBuilder xbrlBuilder) {
|
||||
this.xbrlResultService = xbrlResultService;
|
||||
this.xbrlBuilder = xbrlBuilder;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -36,10 +34,8 @@ public class XBRLReportApiResource {
|
||||
public String retrieveXBRLReport(@QueryParam("startDate") final Date startDate, @QueryParam("endDate") final Date endDate,
|
||||
@QueryParam("currency") final String currency) {
|
||||
|
||||
context.authenticatedUser();
|
||||
final XBRLData data = this.xbrlResultService.getXBRLResult(startDate, endDate, currency);
|
||||
|
||||
String xbrl = xbrlBuilder.build(this.xbrlResultService.getXBRLResult(startDate, endDate, currency));
|
||||
return xbrl;
|
||||
return this.xbrlBuilder.build(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+18
-15
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.taxonomy.api;
|
||||
package org.mifosplatform.mix.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -17,8 +17,8 @@ import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
import org.mifosplatform.xbrl.taxonomy.service.ReadTaxonomyService;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
import org.mifosplatform.mix.service.MixTaxonomyReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -26,19 +26,19 @@ import org.springframework.stereotype.Component;
|
||||
@Path("/mixtaxonomy")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class TaxonomyApiResource {
|
||||
public class MixTaxonomyApiResource {
|
||||
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("taxonomyId", "name", "namespace", "dimension",
|
||||
"description"));
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ToApiJsonSerializer<TaxonomyData> toApiJsonSerializer;
|
||||
private final ReadTaxonomyService readTaxonomyService;
|
||||
private final ToApiJsonSerializer<MixTaxonomyData> toApiJsonSerializer;
|
||||
private final MixTaxonomyReadPlatformService readTaxonomyService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
|
||||
@Autowired
|
||||
public TaxonomyApiResource(final PlatformSecurityContext context, final ToApiJsonSerializer<TaxonomyData> toApiJsonSerializer,
|
||||
final ReadTaxonomyService readTaxonomyService, final ApiRequestParameterHelper apiRequestParameterHelper) {
|
||||
public MixTaxonomyApiResource(final PlatformSecurityContext context, final ToApiJsonSerializer<MixTaxonomyData> toApiJsonSerializer,
|
||||
final MixTaxonomyReadPlatformService readTaxonomyService, final ApiRequestParameterHelper apiRequestParameterHelper) {
|
||||
this.context = context;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.readTaxonomyService = readTaxonomyService;
|
||||
@@ -48,11 +48,14 @@ public class TaxonomyApiResource {
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveTaxonomyList(@Context final UriInfo uriInfo) {
|
||||
context.authenticatedUser();
|
||||
List<TaxonomyData> taxonomyDatas = this.readTaxonomyService.retrieveAllTaxonomy();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, taxonomyDatas, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
public String retrieveAll(@Context final UriInfo uriInfo) {
|
||||
|
||||
}
|
||||
// FIXME - KW - no check for permission to read mix taxonomy data.
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final List<MixTaxonomyData> taxonomyDatas = this.readTaxonomyService.retrieveAll();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, taxonomyDatas, this.RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.mapping.api;
|
||||
package org.mifosplatform.mix.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -21,8 +21,8 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.xbrl.mapping.data.TaxonomyMappingData;
|
||||
import org.mifosplatform.xbrl.mapping.service.ReadTaxonomyMappingService;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyMappingData;
|
||||
import org.mifosplatform.mix.service.MixTaxonomyMappingReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -30,19 +30,19 @@ import org.springframework.stereotype.Component;
|
||||
@Path("/mixmapping")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class TaxonomyMappingApiResource {
|
||||
public class MixTaxonomyMappingApiResource {
|
||||
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("identifier", "config"));
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ToApiJsonSerializer<TaxonomyMappingData> toApiJsonSerializer;
|
||||
private final ReadTaxonomyMappingService readTaxonomyMappingService;
|
||||
private final ToApiJsonSerializer<MixTaxonomyMappingData> toApiJsonSerializer;
|
||||
private final MixTaxonomyMappingReadPlatformService readTaxonomyMappingService;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
|
||||
@Autowired
|
||||
public TaxonomyMappingApiResource(PlatformSecurityContext context, ToApiJsonSerializer<TaxonomyMappingData> toApiJsonSerializer,
|
||||
ReadTaxonomyMappingService readTaxonomyMappingService,
|
||||
public MixTaxonomyMappingApiResource(PlatformSecurityContext context, ToApiJsonSerializer<MixTaxonomyMappingData> toApiJsonSerializer,
|
||||
MixTaxonomyMappingReadPlatformService readTaxonomyMappingService,
|
||||
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||
ApiRequestParameterHelper apiRequestParameterHelper) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TaxonomyMappingApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveTaxonomyMapping(@Context final UriInfo uriInfo) {
|
||||
context.authenticatedUser();
|
||||
TaxonomyMappingData mappingData = this.readTaxonomyMappingService.retrieveTaxonomyMapping();
|
||||
MixTaxonomyMappingData mappingData = this.readTaxonomyMappingService.retrieveTaxonomyMapping();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, mappingData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.mifosplatform.mix.data;
|
||||
|
||||
public class ContextData {
|
||||
|
||||
private final String dimensionType;
|
||||
private final String dimension;
|
||||
private final Integer periodType;
|
||||
|
||||
public ContextData(final String dimensionType, final String dimension, final Integer taxonomyType) {
|
||||
this.dimensionType = dimensionType;
|
||||
this.dimension = dimension;
|
||||
this.periodType = taxonomyType == MixTaxonomyData.BALANCESHEET || taxonomyType == MixTaxonomyData.PORTFOLIO ? 0 : 1;
|
||||
}
|
||||
|
||||
public String getDimensionType() {
|
||||
return this.dimensionType;
|
||||
}
|
||||
|
||||
public String getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
public Integer getPeriodType() {
|
||||
return this.periodType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (this.dimension == null ? 0 : this.dimension.hashCode());
|
||||
result = prime * result + (this.dimensionType == null ? 0 : this.dimensionType.hashCode());
|
||||
result = prime * result + (this.periodType == null ? 0 : this.periodType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (obj == null) { return false; }
|
||||
if (getClass() != obj.getClass()) { return false; }
|
||||
final ContextData other = (ContextData) obj;
|
||||
if (this.dimension == null) {
|
||||
if (other.dimension != null) { return false; }
|
||||
} else if (!this.dimension.equals(other.dimension)) { return false; }
|
||||
if (this.dimensionType == null) {
|
||||
if (other.dimensionType != null) { return false; }
|
||||
} else if (!this.dimensionType.equals(other.dimensionType)) { return false; }
|
||||
if (this.periodType == null) {
|
||||
if (other.periodType != null) { return false; }
|
||||
} else if (!this.periodType.equals(other.periodType)) { return false; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+6
-13
@@ -1,20 +1,22 @@
|
||||
package org.mifosplatform.xbrl.taxonomy.data;
|
||||
package org.mifosplatform.mix.data;
|
||||
|
||||
public class TaxonomyData {
|
||||
public class MixTaxonomyData {
|
||||
|
||||
public static final Integer PORTFOLIO = 0;
|
||||
public static final Integer BALANCESHEET = 1;
|
||||
public static final Integer INCOME = 2;
|
||||
public static final Integer EXPENSE = 3;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String namespace;
|
||||
private final String dimension;
|
||||
private final Integer type;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
|
||||
public TaxonomyData(Long id, String name, String namespace, String dimension, Integer type, String description) {
|
||||
public MixTaxonomyData(final Long id, final String name, final String namespace, final String dimension, final Integer type, final String description) {
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@@ -24,10 +26,6 @@ public class TaxonomyData {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -40,10 +38,6 @@ public class TaxonomyData {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return this.type;
|
||||
}
|
||||
@@ -51,5 +45,4 @@ public class TaxonomyData {
|
||||
public boolean isPortfolio() {
|
||||
return this.type == 5;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -1,11 +1,11 @@
|
||||
package org.mifosplatform.xbrl.mapping.data;
|
||||
package org.mifosplatform.mix.data;
|
||||
|
||||
public class TaxonomyMappingData {
|
||||
public class MixTaxonomyMappingData {
|
||||
|
||||
private final String identifier;
|
||||
private final String config;
|
||||
|
||||
public TaxonomyMappingData(final String identifier, final String config) {
|
||||
public MixTaxonomyMappingData(final String identifier, final String config) {
|
||||
this.identifier = identifier;
|
||||
this.config = config;
|
||||
}
|
||||
@@ -17,5 +17,4 @@ public class TaxonomyMappingData {
|
||||
public String getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.mifosplatform.mix.data;
|
||||
|
||||
public class NamespaceData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String prefix;
|
||||
private final String url;
|
||||
|
||||
public NamespaceData(final Long id, final String prefix, final String url) {
|
||||
|
||||
this.id = id;
|
||||
this.prefix = prefix;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String url() {
|
||||
return this.url;
|
||||
}
|
||||
}
|
||||
+8
-9
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.taxonomy.data;
|
||||
package org.mifosplatform.mix.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
@@ -6,19 +6,19 @@ import java.util.HashMap;
|
||||
|
||||
public class XBRLData {
|
||||
|
||||
private HashMap<TaxonomyData, BigDecimal> resultMap;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private String currency;
|
||||
private final HashMap<MixTaxonomyData, BigDecimal> resultMap;
|
||||
private final Date startDate;
|
||||
private final Date endDate;
|
||||
private final String currency;
|
||||
|
||||
public XBRLData(HashMap<TaxonomyData, BigDecimal> resultMap, Date startDate, Date endDate, String currency) {
|
||||
public XBRLData(final HashMap<MixTaxonomyData, BigDecimal> resultMap, final Date startDate, final Date endDate, final String currency) {
|
||||
this.resultMap = resultMap;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public HashMap<TaxonomyData, BigDecimal> getResultMap() {
|
||||
public HashMap<MixTaxonomyData, BigDecimal> getResultMap() {
|
||||
return this.resultMap;
|
||||
}
|
||||
|
||||
@@ -33,5 +33,4 @@ public class XBRLData {
|
||||
public String getCurrency() {
|
||||
return this.currency;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.mapping.domain;
|
||||
package org.mifosplatform.mix.domain;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@@ -10,7 +10,7 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "mix_taxonomy_mapping")
|
||||
public class TaxonomyMapping extends AbstractPersistable<Long> {
|
||||
public class MixTaxonomyMapping extends AbstractPersistable<Long> {
|
||||
|
||||
@Column(name = "identifier")
|
||||
private String identifier;
|
||||
@@ -21,21 +21,21 @@ public class TaxonomyMapping extends AbstractPersistable<Long> {
|
||||
@Column(name = "currency")
|
||||
private String currency;
|
||||
|
||||
protected TaxonomyMapping() {
|
||||
protected MixTaxonomyMapping() {
|
||||
// default
|
||||
}
|
||||
|
||||
private TaxonomyMapping(final String identifier, final String config, final String currency) {
|
||||
private MixTaxonomyMapping(final String identifier, final String config, final String currency) {
|
||||
this.identifier = StringUtils.defaultIfEmpty(identifier, null);
|
||||
this.config = StringUtils.defaultIfEmpty(config, null);
|
||||
this.currency = StringUtils.defaultIfEmpty(currency, null);
|
||||
}
|
||||
|
||||
public static TaxonomyMapping fromJson(final JsonCommand command) {
|
||||
public static MixTaxonomyMapping fromJson(final JsonCommand command) {
|
||||
final String identifier = command.stringValueOfParameterNamed("identifier");
|
||||
final String config = command.stringValueOfParameterNamed("config");
|
||||
final String currency = command.stringValueOfParameterNamed("currency");
|
||||
return new TaxonomyMapping(identifier, config, currency);
|
||||
return new MixTaxonomyMapping(identifier, config, currency);
|
||||
}
|
||||
|
||||
public void update(final JsonCommand command) {
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.mifosplatform.mix.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface MixTaxonomyMappingRepository extends JpaRepository<MixTaxonomyMapping, Long>, JpaSpecificationExecutor<MixTaxonomyMapping> {
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.exception;
|
||||
package org.mifosplatform.mix.exception;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package org.mifosplatform.xbrl.mapping.handler;
|
||||
package org.mifosplatform.mix.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.xbrl.mapping.service.WriteTaxonomyMappingService;
|
||||
import org.mifosplatform.mix.service.MixTaxonomyMappingWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -11,10 +11,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class UpdateTaxonomyMappingCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final WriteTaxonomyMappingService writeTaxonomyService;
|
||||
private final MixTaxonomyMappingWritePlatformService writeTaxonomyService;
|
||||
|
||||
@Autowired
|
||||
public UpdateTaxonomyMappingCommandHandler(WriteTaxonomyMappingService writeTaxonomyService) {
|
||||
public UpdateTaxonomyMappingCommandHandler(MixTaxonomyMappingWritePlatformService writeTaxonomyService) {
|
||||
this.writeTaxonomyService = writeTaxonomyService;
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import org.mifosplatform.mix.data.MixTaxonomyMappingData;
|
||||
|
||||
public interface MixTaxonomyMappingReadPlatformService {
|
||||
|
||||
MixTaxonomyMappingData retrieveTaxonomyMapping();
|
||||
}
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package org.mifosplatform.xbrl.mapping.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.xbrl.mapping.data.TaxonomyMappingData;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyMappingData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -12,39 +12,39 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReadTaxonomyMappingServiceImpl implements ReadTaxonomyMappingService {
|
||||
public class MixTaxonomyMappingReadPlatformServiceImpl implements MixTaxonomyMappingReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public ReadTaxonomyMappingServiceImpl(final RoutingDataSource dataSource) {
|
||||
public MixTaxonomyMappingReadPlatformServiceImpl(final RoutingDataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
private static final class TaxonomyMappingMapper implements RowMapper<TaxonomyMappingData> {
|
||||
private static final class TaxonomyMappingMapper implements RowMapper<MixTaxonomyMappingData> {
|
||||
|
||||
public String schema() {
|
||||
return "identifier, config " + "from mix_taxonomy_mapping";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaxonomyMappingData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||
public MixTaxonomyMappingData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
final String identifier = rs.getString("identifier");
|
||||
final String config = rs.getString("config");
|
||||
return new TaxonomyMappingData(identifier, config);
|
||||
return new MixTaxonomyMappingData(identifier, config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaxonomyMappingData retrieveTaxonomyMapping() {
|
||||
public MixTaxonomyMappingData retrieveTaxonomyMapping() {
|
||||
try {
|
||||
final TaxonomyMappingMapper rm = new TaxonomyMappingMapper();
|
||||
String sqlString = "select " + rm.schema();
|
||||
final String sqlString = "select " + rm.schema();
|
||||
return this.jdbcTemplate.queryForObject(sqlString, rm);
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package org.mifosplatform.xbrl.mapping.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
|
||||
public interface WriteTaxonomyMappingService {
|
||||
public interface MixTaxonomyMappingWritePlatformService {
|
||||
|
||||
CommandProcessingResult updateMapping(Long mappingId, JsonCommand command);
|
||||
}
|
||||
+10
-16
@@ -1,25 +1,22 @@
|
||||
package org.mifosplatform.xbrl.mapping.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.xbrl.mapping.domain.TaxonomyMapping;
|
||||
import org.mifosplatform.xbrl.mapping.domain.TaxonomyMappingRepository;
|
||||
import org.mifosplatform.mix.domain.MixTaxonomyMapping;
|
||||
import org.mifosplatform.mix.domain.MixTaxonomyMappingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class WriteTaxonomyMappingServiceImpl implements WriteTaxonomyMappingService {
|
||||
public class MixTaxonomyMappingWritePlatformServiceImpl implements MixTaxonomyMappingWritePlatformService {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final TaxonomyMappingRepository mappingRepository;
|
||||
private final MixTaxonomyMappingRepository mappingRepository;
|
||||
|
||||
@Autowired
|
||||
public WriteTaxonomyMappingServiceImpl(final PlatformSecurityContext context, final TaxonomyMappingRepository mappingRepository) {
|
||||
this.context = context;
|
||||
public MixTaxonomyMappingWritePlatformServiceImpl(final MixTaxonomyMappingRepository mappingRepository) {
|
||||
this.mappingRepository = mappingRepository;
|
||||
}
|
||||
|
||||
@@ -27,11 +24,9 @@ public class WriteTaxonomyMappingServiceImpl implements WriteTaxonomyMappingServ
|
||||
@Override
|
||||
public CommandProcessingResult updateMapping(final Long mappingId, final JsonCommand command) {
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
TaxonomyMapping mapping = this.mappingRepository.findOne(mappingId);
|
||||
MixTaxonomyMapping mapping = this.mappingRepository.findOne(mappingId);
|
||||
if (mapping == null) {
|
||||
mapping = TaxonomyMapping.fromJson(command);
|
||||
mapping = MixTaxonomyMapping.fromJson(command);
|
||||
} else {
|
||||
mapping.update(command);
|
||||
}
|
||||
@@ -40,9 +35,8 @@ public class WriteTaxonomyMappingServiceImpl implements WriteTaxonomyMappingServ
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(mapping.getId()).build();
|
||||
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
} catch (final DataIntegrityViolationException dve) {
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
|
||||
public interface MixTaxonomyReadPlatformService {
|
||||
|
||||
List<MixTaxonomyData> retrieveAll();
|
||||
|
||||
MixTaxonomyData retrieveOne(Long id);
|
||||
}
|
||||
+16
-17
@@ -1,27 +1,29 @@
|
||||
package org.mifosplatform.xbrl.taxonomy.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReadTaxonomyServiceImpl implements ReadTaxonomyService {
|
||||
public class MixTaxonomyReadPlatformServiceImpl implements MixTaxonomyReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final MixTaxonomyMapper mixTaxonomyMapper;
|
||||
|
||||
@Autowired
|
||||
public ReadTaxonomyServiceImpl(final RoutingDataSource dataSource) {
|
||||
public MixTaxonomyReadPlatformServiceImpl(final RoutingDataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.mixTaxonomyMapper = new MixTaxonomyMapper();
|
||||
}
|
||||
|
||||
static final class TaxonomyMapper implements RowMapper<TaxonomyData> {
|
||||
private static final class MixTaxonomyMapper implements RowMapper<MixTaxonomyData> {
|
||||
|
||||
public String schema() {
|
||||
return "tx.id as id, name, dimension, type, description, prefix "
|
||||
@@ -29,7 +31,7 @@ public class ReadTaxonomyServiceImpl implements ReadTaxonomyService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaxonomyData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||
public MixTaxonomyData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
final long id = rs.getLong("id");
|
||||
final String name = rs.getString("name");
|
||||
final String namespace = rs.getString("prefix");
|
||||
@@ -37,23 +39,20 @@ public class ReadTaxonomyServiceImpl implements ReadTaxonomyService {
|
||||
final String dimension = rs.getString("dimension");
|
||||
final Integer type = rs.getInt("type");
|
||||
final String desc = rs.getString("description");
|
||||
return new TaxonomyData(id, name, namespace, dimension, type, desc);
|
||||
return new MixTaxonomyData(id, name, namespace, dimension, type, desc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaxonomyData> retrieveAllTaxonomy() {
|
||||
final TaxonomyMapper rm = new TaxonomyMapper();
|
||||
String sql = "select " + rm.schema();
|
||||
return this.jdbcTemplate.query(sql, rm);
|
||||
public List<MixTaxonomyData> retrieveAll() {
|
||||
final String sql = "select " + this.mixTaxonomyMapper.schema();
|
||||
return this.jdbcTemplate.query(sql, this.mixTaxonomyMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaxonomyData retrieveTaxonomyById(Long id) {
|
||||
final TaxonomyMapper rm = new TaxonomyMapper();
|
||||
String sql = "select " + rm.schema() + " where tx.id =" + id;
|
||||
return this.jdbcTemplate.queryForObject(sql, rm);
|
||||
public MixTaxonomyData retrieveOne(final Long id) {
|
||||
final String sql = "select " + this.mixTaxonomyMapper.schema() + " where tx.id =" + id;
|
||||
return this.jdbcTemplate.queryForObject(sql, this.mixTaxonomyMapper);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import org.mifosplatform.mix.data.NamespaceData;
|
||||
|
||||
public interface NamespaceReadPlatformService {
|
||||
|
||||
NamespaceData retrieveNamespaceById(Long id);
|
||||
|
||||
NamespaceData retrieveNamespaceByPrefix(String prefix);
|
||||
}
|
||||
+14
-15
@@ -1,23 +1,25 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.xbrl.report.data.NamespaceData;
|
||||
import org.mifosplatform.mix.data.NamespaceData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReadNamespaceServiceImpl implements ReadNamespaceService {
|
||||
public class NamespaceReadPlatformServiceImpl implements NamespaceReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final NamespaceMapper namespaceMapper;
|
||||
|
||||
@Autowired
|
||||
public ReadNamespaceServiceImpl(final RoutingDataSource dataSource) {
|
||||
public NamespaceReadPlatformServiceImpl(final RoutingDataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.namespaceMapper = new NamespaceMapper();
|
||||
}
|
||||
|
||||
private static final class NamespaceMapper implements RowMapper<NamespaceData> {
|
||||
@@ -27,7 +29,7 @@ public class ReadNamespaceServiceImpl implements ReadNamespaceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||
public NamespaceData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
final long id = rs.getLong("id");
|
||||
final String prefix = rs.getString("prefix");
|
||||
final String url = rs.getString("url");
|
||||
@@ -37,19 +39,16 @@ public class ReadNamespaceServiceImpl implements ReadNamespaceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceData retrieveNamespaceById(Long id) {
|
||||
final NamespaceMapper mapper = new NamespaceMapper();
|
||||
String sql = mapper.schema() + " where id=" + id;
|
||||
public NamespaceData retrieveNamespaceById(final Long id) {
|
||||
final String sql = this.namespaceMapper.schema() + " where id=" + id;
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, mapper);
|
||||
return this.jdbcTemplate.queryForObject(sql, this.namespaceMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceData retrieveNamespaceByPrefix(String prefix) {
|
||||
final NamespaceMapper mapper = new NamespaceMapper();
|
||||
String sql = mapper.schema() + " where prefix='" + prefix + "'";
|
||||
public NamespaceData retrieveNamespaceByPrefix(final String prefix) {
|
||||
final String sql = this.namespaceMapper.schema() + " where prefix='" + prefix + "'";
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, mapper);
|
||||
return this.jdbcTemplate.queryForObject(sql, this.namespaceMapper);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
@@ -10,11 +10,11 @@ import java.util.Map.Entry;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.mifosplatform.xbrl.report.data.ContextData;
|
||||
import org.mifosplatform.xbrl.report.data.NamespaceData;
|
||||
import org.mifosplatform.xbrl.report.exception.XBRLMappingInvalidException;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.XBRLData;
|
||||
import org.mifosplatform.mix.data.ContextData;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
import org.mifosplatform.mix.data.NamespaceData;
|
||||
import org.mifosplatform.mix.data.XBRLData;
|
||||
import org.mifosplatform.mix.exception.XBRLMappingInvalidException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -34,13 +34,13 @@ public class XBRLBuilder {
|
||||
private Integer durationScenarioCounter = 1;
|
||||
|
||||
@Autowired
|
||||
private ReadNamespaceService readNamespaceService;
|
||||
private NamespaceReadPlatformService readNamespaceService;
|
||||
|
||||
public String build(XBRLData xbrlData) {
|
||||
return this.build(xbrlData.getResultMap(), xbrlData.getStartDate(), xbrlData.getEndDate(), xbrlData.getCurrency());
|
||||
}
|
||||
|
||||
public String build(Map<TaxonomyData, BigDecimal> map, Date startDate, Date endDate, String currency) {
|
||||
public String build(Map<MixTaxonomyData, BigDecimal> map, Date startDate, Date endDate, String currency) {
|
||||
instantScenarioCounter = 1;
|
||||
durationScenarioCounter = 1;
|
||||
contextMap = new HashMap<ContextData, String>();
|
||||
@@ -53,8 +53,8 @@ public class XBRLBuilder {
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
|
||||
for (Entry<TaxonomyData, BigDecimal> entry : map.entrySet()) {
|
||||
TaxonomyData taxonomy = entry.getKey();
|
||||
for (Entry<MixTaxonomyData, BigDecimal> entry : map.entrySet()) {
|
||||
MixTaxonomyData taxonomy = entry.getKey();
|
||||
BigDecimal value = entry.getValue();
|
||||
this.addTaxonomy(root, taxonomy, value);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class XBRLBuilder {
|
||||
return doc.asXML();
|
||||
}
|
||||
|
||||
Element addTaxonomy(Element rootElement, TaxonomyData taxonomy, BigDecimal value) {
|
||||
Element addTaxonomy(Element rootElement, MixTaxonomyData taxonomy, BigDecimal value) {
|
||||
|
||||
// throw an error is start / endate is null
|
||||
if (startDate == null || endDate == null) { throw new XBRLMappingInvalidException("start date and end date should not be null"); }
|
||||
@@ -80,7 +80,7 @@ public class XBRLBuilder {
|
||||
NamespaceData ns = readNamespaceService.retrieveNamespaceByPrefix(prefix);
|
||||
if (ns != null) {
|
||||
|
||||
root.addNamespace(prefix, ns.getUrl());
|
||||
root.addNamespace(prefix, ns.url());
|
||||
}
|
||||
qname = prefix + ":" + taxonomy.getName();
|
||||
|
||||
@@ -129,7 +129,7 @@ public class XBRLBuilder {
|
||||
return xmlElement;
|
||||
}
|
||||
|
||||
private String getUnitRef(TaxonomyData tx) {
|
||||
private String getUnitRef(MixTaxonomyData tx) {
|
||||
return tx.isPortfolio() ? UNITID_PURE : UNITID_CUR;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import org.mifosplatform.xbrl.taxonomy.data.XBRLData;
|
||||
import org.mifosplatform.mix.data.XBRLData;
|
||||
|
||||
public interface XBRLResultService {
|
||||
|
||||
+39
-42
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
@@ -13,12 +13,10 @@ import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.xbrl.mapping.data.TaxonomyMappingData;
|
||||
import org.mifosplatform.xbrl.mapping.service.ReadTaxonomyMappingService;
|
||||
import org.mifosplatform.xbrl.report.exception.XBRLMappingInvalidException;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.XBRLData;
|
||||
import org.mifosplatform.xbrl.taxonomy.service.ReadTaxonomyService;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyMappingData;
|
||||
import org.mifosplatform.mix.data.XBRLData;
|
||||
import org.mifosplatform.mix.exception.XBRLMappingInvalidException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
@@ -31,44 +29,44 @@ public class XBRLResultServiceImpl implements XBRLResultService {
|
||||
|
||||
private static final ScriptEngine SCRIPT_ENGINE = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
|
||||
private final ReadTaxonomyMappingService readTaxonomyMappingService;
|
||||
private final ReadTaxonomyService readTaxonomyService;
|
||||
private final MixTaxonomyMappingReadPlatformService readTaxonomyMappingService;
|
||||
private final MixTaxonomyReadPlatformService readTaxonomyService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private HashMap<String, BigDecimal> accountBalanceMap;
|
||||
|
||||
@Autowired
|
||||
public XBRLResultServiceImpl(final RoutingDataSource dataSource, final ReadTaxonomyMappingService readTaxonomyMappingService,
|
||||
final ReadTaxonomyService readTaxonomyService) {
|
||||
public XBRLResultServiceImpl(final RoutingDataSource dataSource, final MixTaxonomyMappingReadPlatformService readTaxonomyMappingService,
|
||||
final MixTaxonomyReadPlatformService readTaxonomyService) {
|
||||
this.readTaxonomyMappingService = readTaxonomyMappingService;
|
||||
this.readTaxonomyService = readTaxonomyService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XBRLData getXBRLResult(Date startDate, Date endDate, String currency) {
|
||||
public XBRLData getXBRLResult(final Date startDate, final Date endDate, final String currency) {
|
||||
|
||||
HashMap<TaxonomyData, BigDecimal> config = this.retrieveTaxonomyConfig(startDate, endDate);
|
||||
final HashMap<MixTaxonomyData, BigDecimal> config = retrieveTaxonomyConfig(startDate, endDate);
|
||||
if (config == null || config.size() == 0) { throw new XBRLMappingInvalidException("Mapping is empty"); }
|
||||
return new XBRLData(config, startDate, endDate, currency);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private HashMap<TaxonomyData, BigDecimal> retrieveTaxonomyConfig(Date startDate, Date endDate) {
|
||||
TaxonomyMappingData taxonomyMapping = this.readTaxonomyMappingService.retrieveTaxonomyMapping();
|
||||
private HashMap<MixTaxonomyData, BigDecimal> retrieveTaxonomyConfig(final Date startDate, final Date endDate) {
|
||||
final MixTaxonomyMappingData taxonomyMapping = this.readTaxonomyMappingService.retrieveTaxonomyMapping();
|
||||
if (taxonomyMapping == null) { return null; }
|
||||
String config = taxonomyMapping.getConfig();
|
||||
final String config = taxonomyMapping.getConfig();
|
||||
if (config != null) {
|
||||
// <taxonomyId, mapping>
|
||||
HashMap<String, String> configMap = new HashMap<String, String>();
|
||||
configMap = new Gson().fromJson(config, configMap.getClass());
|
||||
if (configMap == null) { return null; }
|
||||
// <taxonomyId, value>
|
||||
HashMap<TaxonomyData, BigDecimal> resultMap = new HashMap<TaxonomyData, BigDecimal>();
|
||||
this.setupBalanceMap(this.getAccountSql(startDate, endDate));
|
||||
for (Entry<String, String> entry : configMap.entrySet()) {
|
||||
BigDecimal value = this.processMappingString(entry.getValue());
|
||||
final HashMap<MixTaxonomyData, BigDecimal> resultMap = new HashMap<MixTaxonomyData, BigDecimal>();
|
||||
setupBalanceMap(getAccountSql(startDate, endDate));
|
||||
for (final Entry<String, String> entry : configMap.entrySet()) {
|
||||
final BigDecimal value = processMappingString(entry.getValue());
|
||||
if (value != null) {
|
||||
TaxonomyData taxonomy = readTaxonomyService.retrieveTaxonomyById(Long.parseLong(entry.getKey()));
|
||||
final MixTaxonomyData taxonomy = this.readTaxonomyService.retrieveOne(Long.parseLong(entry.getKey()));
|
||||
resultMap.put(taxonomy, value);
|
||||
}
|
||||
|
||||
@@ -78,8 +76,8 @@ public class XBRLResultServiceImpl implements XBRLResultService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getAccountSql(Date startDate, Date endDate) {
|
||||
String sql = "select debits.glcode as 'glcode', debits.name as 'name', (ifnull(debits.debitamount,0)-ifnull(credits.creditamount,0)) as 'balance' "
|
||||
private String getAccountSql(final Date startDate, final Date endDate) {
|
||||
final String sql = "select debits.glcode as 'glcode', debits.name as 'name', (ifnull(debits.debitamount,0)-ifnull(credits.creditamount,0)) as 'balance' "
|
||||
+ "from (select acc_gl_account.gl_code as 'glcode',name,sum(amount) as 'debitamount' "
|
||||
+ "from acc_gl_journal_entry,acc_gl_account "
|
||||
+ "where acc_gl_account.id = acc_gl_journal_entry.account_id "
|
||||
@@ -136,33 +134,33 @@ public class XBRLResultServiceImpl implements XBRLResultService {
|
||||
return sql;
|
||||
}
|
||||
|
||||
private void setupBalanceMap(String sql) {
|
||||
if (accountBalanceMap == null) {
|
||||
accountBalanceMap = new HashMap<String, BigDecimal>();
|
||||
SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||
private void setupBalanceMap(final String sql) {
|
||||
if (this.accountBalanceMap == null) {
|
||||
this.accountBalanceMap = new HashMap<String, BigDecimal>();
|
||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||
while (rs.next()) {
|
||||
accountBalanceMap.put(rs.getString("glcode"), rs.getBigDecimal("balance"));
|
||||
this.accountBalanceMap.put(rs.getString("glcode"), rs.getBigDecimal("balance"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate Taxonomy value from expression
|
||||
BigDecimal processMappingString(String mappingString) {
|
||||
ArrayList<String> glCodes = this.getGLCodes(mappingString);
|
||||
for (String glcode : glCodes) {
|
||||
private BigDecimal processMappingString(String mappingString) {
|
||||
final ArrayList<String> glCodes = getGLCodes(mappingString);
|
||||
for (final String glcode : glCodes) {
|
||||
|
||||
BigDecimal balance = accountBalanceMap.get(glcode);
|
||||
final BigDecimal balance = this.accountBalanceMap.get(glcode);
|
||||
mappingString = mappingString.replaceAll("\\{" + glcode + "\\}", balance != null ? balance.toString() : "0");
|
||||
}
|
||||
|
||||
// evaluate the expression
|
||||
Float eval = 0f;
|
||||
try {
|
||||
Number value = (Number) SCRIPT_ENGINE.eval(mappingString);
|
||||
final Number value = (Number) SCRIPT_ENGINE.eval(mappingString);
|
||||
if (value != null) {
|
||||
eval = value.floatValue();
|
||||
}
|
||||
} catch (ScriptException e) {
|
||||
} catch (final ScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalArgumentException(e.getMessage());
|
||||
}
|
||||
@@ -170,23 +168,22 @@ public class XBRLResultServiceImpl implements XBRLResultService {
|
||||
return new BigDecimal(eval);
|
||||
}
|
||||
|
||||
ArrayList<String> getGLCodes(String template) {
|
||||
public ArrayList<String> getGLCodes(final String template) {
|
||||
|
||||
ArrayList<String> placeholders = new ArrayList<String>();
|
||||
final ArrayList<String> placeholders = new ArrayList<String>();
|
||||
|
||||
if (template != null) {
|
||||
|
||||
Pattern p = Pattern.compile("\\{(.*?)\\}");
|
||||
Matcher m = p.matcher(template);
|
||||
final Pattern p = Pattern.compile("\\{(.*?)\\}");
|
||||
final Matcher m = p.matcher(template);
|
||||
|
||||
while (m.find()) { // find next match
|
||||
String match = m.group();
|
||||
String code = match.substring(1, match.length() - 1);
|
||||
final String match = m.group();
|
||||
final String code = match.substring(1, match.length() - 1);
|
||||
placeholders.add(code);
|
||||
}
|
||||
|
||||
}
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -11,7 +11,6 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
@@ -58,7 +57,7 @@ public class CalendarsApiResource {
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "entityId", "entityType", "title",
|
||||
"description", "location", "startDate", "endDate", "duration", "type", "repeating", "recurrence", "remindBy", "firstReminder",
|
||||
"secondReminder", "humanReadable", "createdDate", "lastUpdatedDate", "createdByUserId", "createdByUsername",
|
||||
"lastUpdatedByUserId", "lastUpdatedByUsername", "recurringDates","nextTenRecurringDates"));
|
||||
"lastUpdatedByUserId", "lastUpdatedByUsername", "recurringDates", "nextTenRecurringDates"));
|
||||
private final String resourceNameForPermissions = "CALENDAR";
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
@@ -102,7 +101,6 @@ public class CalendarsApiResource {
|
||||
return this.toApiJsonSerializer.serialize(settings, calendarData, this.RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entityType
|
||||
* @param entityId
|
||||
@@ -114,7 +112,7 @@ public class CalendarsApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveCalendarsByEntity(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
|
||||
@Context final UriInfo uriInfo,@DefaultValue("all") @QueryParam("calendarType") String calendarType) {
|
||||
@Context final UriInfo uriInfo, @DefaultValue("all") @QueryParam("calendarType") final String calendarType) {
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
||||
|
||||
@@ -122,18 +120,17 @@ public class CalendarsApiResource {
|
||||
|
||||
Collection<CalendarData> calendarsData = new ArrayList<CalendarData>();
|
||||
|
||||
List<Integer> calendarTypeOptions = CalendarUtils.createIntegerListFromQueryParameter(calendarType);
|
||||
|
||||
final List<Integer> calendarTypeOptions = CalendarUtils.createIntegerListFromQueryParameter(calendarType);
|
||||
|
||||
if (!associationParameters.isEmpty()) {
|
||||
if (associationParameters.contains("parentCalendars")) {
|
||||
calendarsData.addAll(this.readPlatformService.retrieveParentCalendarsByEntity(entityId,
|
||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
|
||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(), calendarTypeOptions));
|
||||
}
|
||||
}
|
||||
|
||||
calendarsData.addAll(this.readPlatformService.retrieveCalendarsByEntity(entityId,
|
||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
|
||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(), calendarTypeOptions));
|
||||
|
||||
// Add recurring dates
|
||||
calendarsData = this.readPlatformService.generateRecurringDates(calendarsData);
|
||||
|
||||
+8
-9
@@ -5,12 +5,10 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.calendar.service;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.portfolio.calendar.data.CalendarData;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.portfolio.calendar.data.CalendarData;
|
||||
|
||||
public interface CalendarReadPlatformService {
|
||||
@@ -18,21 +16,22 @@ public interface CalendarReadPlatformService {
|
||||
CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId);
|
||||
|
||||
Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<Integer> calendarTypeOptions);
|
||||
|
||||
Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<Integer> calendarTypeOptions);
|
||||
|
||||
Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId,
|
||||
List<Integer> calendarTypeOptions);
|
||||
|
||||
Collection<CalendarData> retrieveAllCalendars();
|
||||
|
||||
CalendarData retrieveNewCalendarDetails();
|
||||
|
||||
|
||||
CalendarData generateRecurringDate(final CalendarData calendarData);
|
||||
|
||||
CalendarData generateRecurringDate(final CalendarData calendarData, final LocalDate tillDate);
|
||||
|
||||
|
||||
Collection<CalendarData> generateRecurringDates(final Collection<CalendarData> calendarsData);
|
||||
|
||||
|
||||
CalendarData retrieveLoanCalendar(final Long loanId);
|
||||
|
||||
|
||||
CalendarData retrieveCollctionCalendarByEntity(final Long entityId, final Integer entityTypeId);
|
||||
|
||||
}
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package org.mifosplatform.xbrl.mapping.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface TaxonomyMappingRepository extends JpaRepository<TaxonomyMapping, Long>, JpaSpecificationExecutor<TaxonomyMapping> {
|
||||
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package org.mifosplatform.xbrl.mapping.service;
|
||||
|
||||
import org.mifosplatform.xbrl.mapping.data.TaxonomyMappingData;
|
||||
|
||||
public interface ReadTaxonomyMappingService {
|
||||
|
||||
TaxonomyMappingData retrieveTaxonomyMapping();
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package org.mifosplatform.xbrl.report.data;
|
||||
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
|
||||
public class ContextData {
|
||||
|
||||
private final String dimensionType;
|
||||
private final String dimension;
|
||||
private final Integer periodType;
|
||||
|
||||
public ContextData(String dimensionType, String dimension, Integer taxonomyType) {
|
||||
this.dimensionType = dimensionType;
|
||||
this.dimension = dimension;
|
||||
this.periodType = (taxonomyType == TaxonomyData.BALANCESHEET || taxonomyType == TaxonomyData.PORTFOLIO) ? 0 : 1;
|
||||
}
|
||||
|
||||
public String getDimensionType() {
|
||||
return this.dimensionType;
|
||||
}
|
||||
|
||||
public String getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
public Integer getPeriodType() {
|
||||
return this.periodType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.dimension == null) ? 0 : this.dimension.hashCode());
|
||||
result = prime * result + ((this.dimensionType == null) ? 0 : this.dimensionType.hashCode());
|
||||
result = prime * result + ((this.periodType == null) ? 0 : this.periodType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
ContextData other = (ContextData) obj;
|
||||
if (this.dimension == null) {
|
||||
if (other.dimension != null) return false;
|
||||
} else if (!this.dimension.equals(other.dimension)) return false;
|
||||
if (this.dimensionType == null) {
|
||||
if (other.dimensionType != null) return false;
|
||||
} else if (!this.dimensionType.equals(other.dimensionType)) return false;
|
||||
if (this.periodType == null) {
|
||||
if (other.periodType != null) return false;
|
||||
} else if (!this.periodType.equals(other.periodType)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.mifosplatform.xbrl.report.data;
|
||||
|
||||
public class NamespaceData {
|
||||
|
||||
private final Long id;
|
||||
private final String prefix;
|
||||
private final String url;
|
||||
|
||||
public NamespaceData(Long id, String prefix, String url) {
|
||||
|
||||
this.id = id;
|
||||
this.prefix = prefix;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
|
||||
import org.mifosplatform.xbrl.report.data.NamespaceData;
|
||||
|
||||
public interface ReadNamespaceService {
|
||||
|
||||
NamespaceData retrieveNamespaceById(Long id);
|
||||
|
||||
NamespaceData retrieveNamespaceByPrefix(String prefix);
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package org.mifosplatform.xbrl.taxonomy.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
|
||||
public interface ReadTaxonomyService {
|
||||
|
||||
List<TaxonomyData> retrieveAllTaxonomy();
|
||||
|
||||
TaxonomyData retrieveTaxonomyById(Long id);
|
||||
}
|
||||
+6
-5
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.report.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -8,24 +8,25 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.mix.service.XBRLResultServiceImpl;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ReadTaxonomyMappingServiceImplTest {
|
||||
|
||||
XBRLResultServiceImpl readService;
|
||||
private XBRLResultServiceImpl readService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RoutingDataSource dataSource = Mockito.mock(RoutingDataSource.class);
|
||||
readService = new XBRLResultServiceImpl(dataSource, null, null);
|
||||
final RoutingDataSource dataSource = Mockito.mock(RoutingDataSource.class);
|
||||
this.readService = new XBRLResultServiceImpl(dataSource, null, null);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCorrectlyGetGLCode() {
|
||||
ArrayList<String> result = readService.getGLCodes("{12000}+{11000}");
|
||||
final ArrayList<String> result = this.readService.getGLCodes("{12000}+{11000}");
|
||||
assertEquals("12000", result.get(0));
|
||||
assertEquals("11000", result.get(1));
|
||||
}
|
||||
+9
-7
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.xbrl.report.service;
|
||||
package org.mifosplatform.mix.report.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -16,8 +16,10 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mifosplatform.xbrl.report.data.NamespaceData;
|
||||
import org.mifosplatform.xbrl.taxonomy.data.TaxonomyData;
|
||||
import org.mifosplatform.mix.data.MixTaxonomyData;
|
||||
import org.mifosplatform.mix.data.NamespaceData;
|
||||
import org.mifosplatform.mix.service.NamespaceReadPlatformServiceImpl;
|
||||
import org.mifosplatform.mix.service.XBRLBuilder;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
@@ -29,14 +31,14 @@ import org.xml.sax.SAXException;
|
||||
public class XBRLBuilderTest {
|
||||
|
||||
@Mock
|
||||
private ReadNamespaceServiceImpl readNamespaceService;
|
||||
private NamespaceReadPlatformServiceImpl readNamespaceService;
|
||||
@InjectMocks
|
||||
private XBRLBuilder xbrlBuilder = new XBRLBuilder();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
readNamespaceService = Mockito.mock(ReadNamespaceServiceImpl.class);
|
||||
readNamespaceService = Mockito.mock(NamespaceReadPlatformServiceImpl.class);
|
||||
when(readNamespaceService.retrieveNamespaceByPrefix(Mockito.anyString())).thenReturn(
|
||||
new NamespaceData(1l, "mockedprefix", "mockedurl"));
|
||||
|
||||
@@ -45,8 +47,8 @@ public class XBRLBuilderTest {
|
||||
@Test
|
||||
public void shouldCorrectlyBuildMap() {
|
||||
|
||||
HashMap<TaxonomyData, BigDecimal> map = new HashMap<TaxonomyData, BigDecimal>();
|
||||
TaxonomyData data1 = Mockito.mock(TaxonomyData.class);
|
||||
HashMap<MixTaxonomyData, BigDecimal> map = new HashMap<MixTaxonomyData, BigDecimal>();
|
||||
MixTaxonomyData data1 = Mockito.mock(MixTaxonomyData.class);
|
||||
when(data1.getName()).thenReturn("Assets");
|
||||
map.put(data1, new BigDecimal(10000));
|
||||
String result = xbrlBuilder.build(map, Date.valueOf("2005-11-11"), Date.valueOf("2013-07-17"), "USD");
|
||||
Reference in New Issue
Block a user