review changes to yanna pull request for mix-xbrl GSOC project.

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