Project

General

Profile

Revision 5df69434

ID5df694340b2696cca7f89b65da12c0ac0042d7ad
Parent 9aaf46e7
Child 4e201def

Added by Katja Luther about 5 years ago

minor

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
612 612

  
613 613
        Classification classification = parent.getClassification();
614 614
        //FIXME also set the tree index here for performance reasons
615
        classification = HibernateProxyHelper.deproxy(classification, Classification.class);
615 616
        setClassificationRecursively(classification);
616 617

  
617 618
        // add this node to the parent's child nodes
619
        parent = HibernateProxyHelper.deproxy(parent, TaxonNode.class);
618 620
        List<TaxonNode> parentChildren = parent.getChildNodes();
619 621
       //TODO: Only as a workaround. We have to find out why merge creates null entries.
620 622
        while (parentChildren.contains(null)){
621 623
            parentChildren.remove(null);
622 624
        }
623
        this.updateSortIndex(0);
625
        parent.updateSortIndex(0);
624 626
        if (parentChildren.contains(this)){
625 627
            //avoid duplicates
626 628
            if (parentChildren.indexOf(this) < index){
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/PostMergeEntityListener.java
66 66
                }
67 67
            }
68 68
        }
69

  
70

  
69 71
    }
70 72

  
71 73
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/UpdateEntityListener.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.persistence.hibernate;
11 11

  
......
26 26
	@SuppressWarnings("unused")
27 27
	private static final Logger logger = Logger.getLogger(UpdateEntityListener.class);
28 28

  
29
	public void onSaveOrUpdate(SaveOrUpdateEvent event)	throws HibernateException {
29
	@Override
30
    public void onSaveOrUpdate(SaveOrUpdateEvent event)	throws HibernateException {
30 31
		Object entity = event.getObject();
31 32
		if(entity != null && VersionableEntity.class.isAssignableFrom(entity.getClass())) {
32
			
33

  
33 34
			VersionableEntity versionableEntity = (VersionableEntity)entity;
34 35
			versionableEntity.setUpdated(new DateTime());
35 36
			Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
......
40 41
			 if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), entity, CdmPermission.UPDATE)){
41 42
						throw new EvaluationFailedException("Permission evaluation failed for " + event.getEntity());
42 43
			  }*/
43
			} 
44
			}
44 45
		}
46

  
47

  
45 48
	}
46 49
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/AgentServiceImpl.java
173 173

  
174 174
	@Override
175 175
	@Transactional(readOnly = false)
176
	public Person convertTeam2Person(UUID teamUuid) throws MergeException {
176
	public UpdateResult convertTeam2Person(UUID teamUuid) throws MergeException {
177 177
	    Team team = CdmBase.deproxy(dao.load(teamUuid), Team.class);
178 178
	    return convertTeam2Person(team);
179 179
	}
180 180

  
181 181
	@Override
182
	public Person convertTeam2Person(Team team) throws MergeException {
183
		Person result = null;
182
	public UpdateResult convertTeam2Person(Team team) throws MergeException {
183
        UpdateResult result = new UpdateResult();
184
        Person newPerson = null;
184 185
		team = CdmBase.deproxy(team, Team.class);
185 186
		if (team.getTeamMembers().size() > 1){
186 187
			throw new IllegalArgumentException("Team must not have more than 1 member to be convertable into a person");
187 188
		}else if (team.getTeamMembers().size() == 1){
188
			result = team.getTeamMembers().get(0);
189
		    newPerson = team.getTeamMembers().get(0);
189 190
			IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
190 191
			strategy.setDefaultCollectionMergeMode(MergeMode.FIRST);
191
			genericDao.merge(result, team, strategy);
192
			genericDao.merge(newPerson, team, strategy);
192 193
		}else if (team.getTeamMembers().isEmpty()){
193
			result = Person.NewInstance();
194
			genericDao.save(result);
194
		    newPerson = Person.NewInstance();
195
            genericDao.save(newPerson);
195 196
			IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
196 197
			strategy.setDefaultMergeMode(MergeMode.SECOND);
197 198
			strategy.setDefaultCollectionMergeMode(MergeMode.SECOND);
198
			genericDao.merge(result, team, strategy);
199
			genericDao.merge(newPerson, team, strategy);
199 200
		}else{
200 201
			throw new IllegalStateException("Unhandled state of team members collection");
201 202
		}
202

  
203
		result.setCdmEntity(newPerson);
203 204
		return result;
204 205
	}
205 206

  
206 207
	@Override
207 208
	@Transactional(readOnly = false)
208
	public Team convertPerson2Team(UUID personUuid) throws MergeException, IllegalArgumentException {
209
	public UpdateResult convertPerson2Team(UUID personUuid) throws MergeException, IllegalArgumentException {
209 210
	    Person person = CdmBase.deproxy(dao.load(personUuid), Person.class);
210 211
	    return convertPerson2Team(person);
211 212
	}
212 213

  
213 214
	@Override
214
	public Team convertPerson2Team(Person person) throws MergeException, IllegalArgumentException {
215
		Team team = Team.NewInstance();
215
	public UpdateResult convertPerson2Team(Person person) throws MergeException, IllegalArgumentException {
216
	    UpdateResult result = new UpdateResult();
217
        Team team = Team.NewInstance();
216 218
		ConvertMergeStrategy strategy = ConvertMergeStrategy.NewInstance(TeamOrPersonBase.class);
217 219
		strategy.setDefaultMergeMode(MergeMode.SECOND);
218 220
		strategy.setDefaultCollectionMergeMode(MergeMode.SECOND);
......
235 237
		} catch (Exception e) {
236 238
			throw new MergeException("Unhandled merge exception", e);
237 239
		}
238
		return team;
240
		result.setCdmEntity(team);
241
        return result;
239 242
	}
240 243

  
241 244

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IAgentService.java
113 113
     * @return
114 114
     * @throws MergeException
115 115
     */
116
    public Person convertTeam2Person(UUID teamUuid) throws MergeException;
116
    public UpdateResult convertTeam2Person(UUID teamUuid) throws MergeException;
117 117

  
118 118
	/**
119 119
	 * If the given {@link Team} is a single member team all links to the team are redirected to the
......
129 129
	 * @throws IllegalArgumentException if team has > 1 members
130 130
	 * @throws MergeException if anything else goes wrong during merge
131 131
	 */
132
	public Person convertTeam2Person(Team team) throws MergeException, IllegalArgumentException;
132
	public UpdateResult convertTeam2Person(Team team) throws MergeException, IllegalArgumentException;
133 133

  
134 134

  
135 135
    /**
......
138 138
     * @throws MergeException
139 139
     * @throws IllegalArgumentException
140 140
     */
141
    public Team convertPerson2Team(UUID personUuid) throws MergeException, IllegalArgumentException;
141
    public UpdateResult convertPerson2Team(UUID personUuid) throws MergeException, IllegalArgumentException;
142 142

  
143 143
	/**
144 144
	 * If possible replaces the given person by a new {@link Team}.
......
151 151
	 * @return the new team that replaces the given person
152 152
	 * @throws MergeException if anything else goes wrong during merge
153 153
	 */
154
	public Team convertPerson2Team(Person person) throws MergeException, IllegalArgumentException;
154
	public UpdateResult convertPerson2Team(Person person) throws MergeException, IllegalArgumentException;
155 155

  
156 156

  
157 157

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
524 524
    @Override
525 525
    @Transactional
526 526
    public UpdateResult moveTaxonNode(UUID taxonNodeUuid, UUID targetNodeUuid, boolean isParent){
527
        TaxonNode taxonNode = dao.load(taxonNodeUuid);
528
    	TaxonNode targetNode = dao.load(targetNodeUuid);
527
        TaxonNode taxonNode = HibernateProxyHelper.deproxy(dao.load(taxonNodeUuid), TaxonNode.class);
528
    	TaxonNode targetNode = HibernateProxyHelper.deproxy(dao.load(targetNodeUuid), TaxonNode.class);
529 529
    	return moveTaxonNode(taxonNode, targetNode, isParent);
530 530
    }
531 531

  
......
545 545
        result.addUpdatedObject(newParent);
546 546
        result.addUpdatedObject(taxonNode.getParent());
547 547
        result.setCdmEntity(taxonNode);
548
        newParent.addChildNode(taxonNode, sortIndex, taxonNode.getReference(),  taxonNode.getMicroReference());
548
        if (!isParent){
549
            newParent.getParent().addChildNode(taxonNode, sortIndex, taxonNode.getReference(),  taxonNode.getMicroReference());
550
        } else{
551
            newParent.addChildNode(taxonNode, sortIndex, taxonNode.getReference(),  taxonNode.getMicroReference());
552
        }
549 553
        dao.saveOrUpdate(newParent);
550 554

  
551 555
        return result;
......
591 595
        try{
592 596
            child = parent.addChildTaxon(newTaxon, parent.getReference(), parent.getMicroReference());
593 597
        }catch(Exception e){
594
            logger.error("TaxonNode could not be created. "+ e.getLocalizedMessage());
595 598
            result.addException(e);
599
            result.setError();
596 600
        }
597 601
//        child = dao.save(child);
598 602

  
599 603
        dao.saveOrUpdate(parent);
600 604
        result.addUpdatedObject(parent);
601
        result.setCdmEntity(child);
605
        if (child != null){
606
            result.setCdmEntity(child);
607
        }
602 608
        return result;
603 609

  
604 610
    }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/AgentServiceImplTest.java
60 60
    	nameSerivce.save(name);
61 61

  
62 62
    	Team team = null;
63
    	UpdateResult result = null;
63 64
		try {
64
			team = service.convertPerson2Team(person);
65
		    result = service.convertPerson2Team(person);
66
		    team = (Team) result.getCdmEntity();
65 67
		} catch (MergeException e) {
66 68
			Assert.fail("No Merge exception should be thrown");
67 69
		}
......
95 97
    	service.save(team);
96 98
    	nameSerivce.save(name);
97 99

  
100
    	UpdateResult result = null;
98 101
    	Person person = null;
99 102
		try {
100
			person = service.convertTeam2Person(team);
103
			result = service.convertTeam2Person(team);
104
			person = (Person)result.getCdmEntity();
101 105
		} catch (IllegalArgumentException e) {
102 106
			Assert.fail("No IllegalArgumentException should be thrown");
103 107
		} catch (MergeException e) {
......
135 139
    	nameSerivce.save(name);
136 140

  
137 141
    	Person person = null;
142
    	UpdateResult result = null;
138 143
		try {
139
			person = service.convertTeam2Person(team);
144
		    result = service.convertTeam2Person(team);
145
		    person = (Person) result.getCdmEntity();
140 146
		} catch (IllegalArgumentException e) {
141 147
			Assert.fail("No IllegalArgumentException should be thrown");
142 148
		} catch (MergeException e) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)