Project

General

Profile

« Previous | Next » 

Revision 50141

1. Bug fix on statistics
2. Unitest for alternative bids

View differences:

modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/AlternativeFundingBidsTest.java
36 36

  
37 37
    @Test
38 38
    @Transactional
39
    @Rollback(true)
39
    //@Rollback(true)
40 40
    public void importAlternativeFundingBids(){
41 41

  
42 42
        String path = "/home/panagiotis/Desktop/uploadFiles/";
......
63 63
                    System.out.println("Organization " + organization +  "  not exists!");
64 64
                    //org = organizationManager.createOrganization(organization);
65 65
                }
66
//                Organization org = (Organization) organizationManager.search(organization).get(0);
66
                Organization org = (Organization) organizationManager.search(organization).get(0);
67 67
                bid = this.initializeBid(funding_name,id,totalAmount,contractStartDate,contractEndDate);
68 68
                bid.setFirstInvoice(this.uploadInvoiceFile(path,funding_name,FIRST_INVOICE_PDF));
69 69
                bid.setSecondInvoice(this.uploadInvoiceFile(path,funding_name,SECOND_INVOICE_PDF));
......
99 99
            contractFile.setFile(baos.toByteArray());
100 100

  
101 101

  
102

  
102 103
        } catch (IOException e) {
103 104
            e.printStackTrace();
104 105
        }
......
125 126
            bankTransferReceipt = new BankTransferReceipt();
126 127
            bankTransferReceipt.setContent(baos.toByteArray());
127 128
            bankTransferReceipt.setContentType(contentType);
129

  
128 130
            //TODO add date etc
129 131
        } catch (IOException e) {
130 132
            e.printStackTrace();
......
183 185
        }
184 186
        return invoice;
185 187
    }
188

  
186 189
}
modules/uoa-goldoa-service/branches/hibernate/src/test/resources/applicationContext-goldoa-service-test.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
       xmlns:tx="http://www.springframework.org/schema/tx"
4
       xmlns="http://www.springframework.org/schema/beans"
5
       xmlns:context="http://www.springframework.org/schema/context"
6
       xmlns:aop="http://www.springframework.org/schema/aop"
3
	   xmlns:tx="http://www.springframework.org/schema/tx"
4
	   xmlns="http://www.springframework.org/schema/beans"
5
	   xmlns:context="http://www.springframework.org/schema/context"
6
	   xmlns:aop="http://www.springframework.org/schema/aop"
7 7

  
8
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
8
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
9 9
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
10 10
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
11 11
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
12 12

  
13
 	<!-- Database Configuration -->
13
	<!-- Database Configuration -->
14 14
	<import resource="hibernate-cfg.xml"/>
15 15
	<import resource="dataSource.xml"/>
16 16

  
17 17
	<aop:aspectj-autoproxy proxy-target-class="true" />
18 18
	<tx:annotation-driven transaction-manager="txManager"/>
19 19

  
20
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
20
	<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
21 21
		<property name="sessionFactory" ref="sessionFactory"/>
22 22
	</bean>
23 23

  
24 24
	<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newCachedThreadPool" destroy-method="shutdown" />
25 25

  
26
	<context:property-placeholder location="classpath*:/eu/**/applicationContext-goldoa-service.properties" />
27

  
28
	<context:component-scan base-package="eu.dnetlib.goldoa.*" />
26 29
	<context:annotation-config/>
27

  
28
	<context:property-placeholder location="classpath:applicationContext-goldoa-service.properties" />
29

  
30
	<context:component-scan base-package="eu.dnetlib.goldoa.service" />
31
	<context:component-scan base-package="eu.dnetlib.goldoa.service.utils" />
32
	<context:component-scan base-package="eu.dnetlib.goldoa.service.dao" />
33

  
34
	<context:component-scan base-package="eu.dnetlib.goldoa.domain" />
35

  
36
</beans>
30
</beans>
modules/uoa-goldoa-service/branches/hibernate/src/test/resources/hibernate-cfg.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2

  
3 3
<!DOCTYPE hibernate-configuration PUBLIC
4
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
5
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
4
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
5
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
6 6

  
7 7

  
8 8
<hibernate-configuration>
9
    <session-factory>
9
	<session-factory>
10 10
		<property name="hibernate.hbm2ddl.auto">update</property>
11 11
		<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
12
		<property name="show_sql">false</property>
13 12
		<property name="connection.pool_size">1</property>
14
		<property name="format_sql">true</property>
13
		<!--<property name="format_sql">true</property>-->
14
		<!-- enable second level cache and query cache -->
15
		<!--	<property name="hibernate.cache.use_second_level_cache">true</property>
16
            <property name="hibernate.cache.region.factory_class">org.hibernate.cache.jcache.JCacheRegionFactory</property>
17
            <property name="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</property>
18
            <property name="hibernate.cache.use_query_cache">true</property>-->
15 19

  
16 20

  
17 21
		<mapping class = "eu.dnetlib.goldoa.domain.User"/>
......
20 24
		<mapping class = "eu.dnetlib.goldoa.domain.UserRolePK"/>
21 25
		<mapping class = "eu.dnetlib.goldoa.domain.Organization"/>
22 26
		<mapping class = "eu.dnetlib.goldoa.domain.Affiliation"/>
23

  
24 27
		<mapping class = "eu.dnetlib.goldoa.domain.Country"/>
25 28
		<mapping class = "eu.dnetlib.goldoa.domain.File"/>
26 29
		<mapping class = "eu.dnetlib.goldoa.domain.Funder"/>
......
48 51
		<mapping class = "eu.dnetlib.goldoa.domain.BankAccount"/>
49 52
		<mapping class = "eu.dnetlib.goldoa.domain.BankTransferReceipt"/>
50 53
		<mapping class = "eu.dnetlib.goldoa.domain.BudgetContract"/>
51
    </session-factory>
52
</hibernate-configuration>
54
		<mapping class = "eu.dnetlib.goldoa.domain.AlternativeFundingBid"/>
55
	</session-factory>
56
</hibernate-configuration>
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/RequestManagerImpl.java
672 672
			String identifierValue = !line[8].equals("")?line[8].trim():null;
673 673
			String apc = !line[9].equals("")?line[9].trim():"0";
674 674
			String apcCurrency = !line[10].equals("")?line[10].trim():null;
675
			String discount = line.length>11?line[11].trim():"0";
675
			String discount = !line[11].equals("")?line[11].trim():null;
676
			String status = line.length>12?line[12].trim():"0";
676 677

  
678
			LOGGER.debug(discount + "/" + status);
679

  
677 680
			importRequestFromCSV(firstname,lastname,organization,email,
678 681
					grant,doi,acceptanceDate, identifierType,
679
					identifierValue,apc, apcCurrency,discount);
682
					identifierValue,apc, apcCurrency,discount,status);
680 683
		}
681 684
	}
682 685

  
......
684 687
	private void importRequestFromCSV(String firstname, String lastname, String organization, String email, String grant,
685 688
									  String doi, String acceptanceDate,
686 689
									  String identifierType, String identifierValue,
687
									  String apc, String apcCurrency, String discount)
690
									  String apc, String apcCurrency, String discount, String status)
688 691
			throws PersonManagerException, ParseException, ManagerException, OrganizationManagerException {
689 692

  
690 693
		List<Object> orgs =  organizationManager.search(organization);
......
730 733

  
731 734

  
732 735
		Request request = requestDAO.getRequestFromCSV(user,project,publication,org,
733
				acceptanceDate, identifierType,identifierValue,apc, apcCurrency,discount);
736
				acceptanceDate, identifierType,identifierValue,apc, apcCurrency,discount,status);
734 737

  
735 738
		request.setId("L" + new SimpleDateFormat("yyyyMMdd-").format(new Date()) + requestDAO.getRequestId());
736 739
		request.setEligibility(Eligibility.OK);
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/RequestDAO.java
827 827

  
828 828
	public Request getRequestFromCSV(User user, Project project, Publication publication, Organization organization,
829 829
									 String acceptanceDate, String identifierType, String identifierValue,
830
									 String apc, String apcCurrency, String discount) throws ParseException {
830
									 String apc, String apcCurrency, String discount, String status) throws ParseException {
831 831

  
832 832
		Request request = new Request();
833 833
		request.setProject(project);
......
849 849
		publication.getIdentifiers().add(id);
850 850

  
851 851
		request.setOrganization(organization);
852
		request.setApc(apc!=null?Float.parseFloat(apc):null);
852

  
853
		float APC  = Float.parseFloat(apc);
854

  
855
		request.setApc(APC);
856
		request.setApcPaid(APC);
857

  
858
		if(discount != null){
859
			float disc = Float.parseFloat(discount);
860
			float fundingRequested = APC - (disc*APC / 100);
861
			request.setProjectparticipation(100-disc);
862
			request.setDiscount(disc);
863
			request.setFundingrequested(fundingRequested);
864
		}else {
865
			request.setDiscount((float) 0);
866
			request.setFundingrequested(APC);
867
			request.setProjectparticipation((float) 100);
868
		}
869

  
853 870
		request.setCurrency(apcCurrency!=null?Currency.valueOf(apcCurrency):null);
854
		request.setDiscount(discount!=null?Float.parseFloat(discount):null);
871

  
855 872
		request.setPublication(publication);
856
		request.setStatus(Request.RequestStatus.LIBRARY_FUND_PAID);
873
		request.setStatus(Request.RequestStatus.forStatus(Integer.parseInt(status)));
857 874
		return request;
858 875
	}
859 876
}
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/stats/StatsManagerImpl.java
159 159
			List<Quadruple<String, Integer, Float, Float>> l = new ArrayList<>();
160 160
			for(Object[] rs : resultSet){
161 161
				if(rs[0] == null) rs[0] = "";
162
				if(rs[2] == null) rs[2] = "0.0";
163
				if(rs[3] == null) rs[3] = "0.0";
162
				//if(rs[2] == null) rs[2] = "0.0";
163
//				if(rs[3] == null) rs[3] = "0.0";
164 164

  
165

  
166
				if(category != Series.Category.STATUS)
167
					q = new Quadruple<>(rs[0].toString(),
168
							Integer.parseInt(rs[1].toString()), Float.parseFloat(rs[2].toString()), Float.parseFloat(rs[3].toString()));
169
				else
170
					q = new Quadruple<>(Request.RequestStatus.forStatus((Integer) rs[0]).getValue(),
171
							Integer.parseInt(rs[1].toString()), Float.parseFloat(rs[2].toString()), Float.parseFloat(rs[3].toString()));
172
				l.add(q);
165
				if(rs[2] != null && rs[3] != null){
166
					if(category != Series.Category.STATUS)
167
						q = new Quadruple<>(rs[0].toString(),
168
								Integer.parseInt(rs[1].toString()), Float.parseFloat(rs[2].toString()), Float.parseFloat(rs[3].toString()));
169
					else
170
						q = new Quadruple<>(Request.RequestStatus.forStatus((Integer) rs[0]).getValue(),
171
								Integer.parseInt(rs[1].toString()), Float.parseFloat(rs[2].toString()), Float.parseFloat(rs[3].toString()));
172
					l.add(q);
173
				}
174
				
173 175
			}
174 176
			map.put(category,l);
175 177
		}
......
285 287

  
286 288
		sb.append(" order by ").append(dateColumn);
287 289

  
288
//		System.out.println(sb.toString());return null;
289 290

  
290 291
		List<Object[]> resultSet = sessionFactory.getCurrentSession().createSQLQuery(sb.toString()).list();
291 292
		List<Triple<Date, Integer, Float>> l = new ArrayList<>();
......
293 294
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.s");
294 295
		for(Object[] rs : resultSet){
295 296
			Date date = null;
297

  
296 298
			try {
297 299
				if(rs[0] == null)
298 300
					date = null;
299 301
				else
300 302
					date = formatter.parse(rs[0].toString());
301
				if(rs[2] == null)
302
					rs[2] = "0.0";
303
				Triple<Date, Integer, Float> t = new Triple<Date,Integer, Float>(date,
304
						Integer.parseInt(rs[1].toString()),Float.parseFloat(rs[2].toString()));
305
				l.add(t);
303
				if(rs[2] != null){
304
					//rs[2] = "0.0";
305
					Triple<Date, Integer, Float> t = new Triple<Date,Integer, Float>(date,
306
							Integer.parseInt(rs[1].toString()),Float.parseFloat(rs[2].toString()));
307
					l.add(t);
308
				}
309

  
306 310
			} catch (ParseException e) {
307 311
				e.printStackTrace();
308 312
			}

Also available in: Unified diff