Project

General

Profile

« Previous | Next » 

Revision 57188

removed project reference from src/test/resources/eu/dnetlib/data/transform/odf.xml, the test didn't include any check against it

View differences:

SoftwareEventFactory.java
44 44

  
45 45
	public static List<EventWrapper> process(final Context context, final Oaf current, final Oaf other, final Float trust, final Map<String, String> baseUrlMap)
46 46
			throws IOException, InterruptedException, DocumentException {
47

  
48
		/*
49
		 * if (!current.getRel().hasCachedOafTarget() || (other != null && !other.getRel().hasCachedOafTarget())) {
50
		 * context.getCounter(COUNTER_GROUP, "events skipped: missing project 2nd step").increment(1); return; }
51
		 */
52

  
53 47
		return new SoftwareEventFactory(baseUrlMap).processSoftware(context, current, other, trust);
54 48
	}
55 49

  
......
67 61

  
68 62
				final String provenance = oafRel.getDataInfo().getProvenanceaction().getClassid();
69 63
				if (inferenceProvenance.contains(provenance)) {
70
					final OafEntity result = oafRel.getRel().getCachedOafTarget().getEntity();
71
					events.add(doProcessSoftware(context, current, current, result, provenance, Topic.ENRICH_MISSING_SOFTWARE, trust(trust, oafRel)));
64
					final Software software = mapRelatedSoftware(oafRel.getRel().getCachedOafTarget().getEntity().getResult());
65
					events.add(doProcessSoftware(context, current, current, software, provenance, Topic.ENRICH_MISSING_SOFTWARE, trust(trust, oafRel)));
72 66
				}
73 67
			}
74 68
		} else {
......
82 76

  
83 77
						final String provenance = otherOafRel.getDataInfo().getProvenanceaction().getClassid();
84 78

  
85
						final OafEntity software = otherOafRel.getRel().getCachedOafTarget().getEntity();
79
						final OafEntity swEntity = otherOafRel.getRel().getCachedOafTarget().getEntity();
80
						final Software software = mapRelatedSoftware(swEntity.getResult());
86 81

  
87 82
						final boolean currentHasSw = Iterables.tryFind(current.getEntity().getCachedOafRelList(), oaf -> {
88 83
							final String currentSwId = oaf.getRel().getCachedOafTarget().getEntity().getId();
89
							// System.out.println(String.format("%s = %s ? %s", currentProjectId, project.getId(),
90
							// currentProjectId.equals(project.getId())));
91
							return currentSwId.equals(software.getId());
84
							return currentSwId.equals(swEntity.getId());
92 85
						}).isPresent();
93 86

  
94 87
						if (!currentHasSw) {
95
							// System.out.println(String.format("generating event for other = %s\n\nproject = %s", other, project));
96
							events.add(doProcessSoftware(context, current, other, software, provenance, Topic.ENRICH_MISSING_PROJECT,
88
							events.add(doProcessSoftware(context, current, other, software, provenance, Topic.ENRICH_MISSING_SOFTWARE,
97 89
									trust(trust, currentOafRel)));
98 90
						}
99 91
					}
......
106 98
	private EventWrapper doProcessSoftware(final Context context,
107 99
			final Oaf current,
108 100
			final Oaf other,
109
			final OafEntity software,
101
			final Software software,
110 102
			final String provenance,
111 103
			final Topic topic,
112 104
			final Float trust)
......
117 109

  
118 110
		final Provenance prov = getProvenance(otherEntity, provenance);
119 111

  
120
		final OpenAireEventPayload payload = addSoftware(OpenAireEventPayloadFactory.fromOAF(currentEntity, trust, prov), software);
112
		final OpenAireEventPayload payload = OpenAireEventPayloadFactory.fromOAF(currentEntity, trust, prov);
121 113

  
122
		final EventMessage event = asEvent(currentEntity, topic, payload, otherEntity, trust);
123
		event.setPayload(HighlightFactory.highlightEnrichSoftware(payload, software, provenance).toJSON());
124
		return EventWrapper.newInstance(event,
125
				payload.getHighlight().getSoftwares().stream().filter(Objects::nonNull).map(s -> s.getName()).sorted()
126
						.collect(Collectors.joining(", ")),
127
				topic.getValue());
128
	}
129

  
130
	private OpenAireEventPayload addSoftware(final OpenAireEventPayload payload, final OafEntity software) {
131 114
		final Map<String, Software> swMap = Maps.newHashMap();
132 115
		for (final Software s : payload.getPublication().getSoftwares()) {
133 116
			swMap.put(s.getLandingPage(), s);
134 117
		}
135
		final Software hlSw = mapRelatedSoftware(software.getResult());
136
		swMap.put(hlSw.getLandingPage(), hlSw);
137 118

  
119
		swMap.put(software.getLandingPage(), software);
120

  
138 121
		payload.getPublication().setSoftwares(Lists.newArrayList(swMap.values()));
122
		payload.getHighlight().setSoftwares(Lists.newArrayList(software));
139 123

  
140
		return payload;
124
		final EventMessage event = asEvent(currentEntity, topic, payload, otherEntity, trust);
125

  
126
		event.setPayload(payload.toJSON());
127
		return EventWrapper.newInstance(event,
128
				payload.getHighlight().getSoftwares().stream().filter(Objects::nonNull).map(s -> s.getName()).sorted()
129
						.collect(Collectors.joining(", ")),
130
				topic.getValue());
141 131
	}
142 132

  
143 133
	private Provenance getProvenance(final OafEntity entity, final String provenance) {

Also available in: Unified diff