/** * Update the calculated person data. This method and updateCalculatedPersonOnDeleteOfSor need to * be generalized to handle recalculations. * * @param toPerson * @param fromPerson * @param sorPerson Adjust calculated roles... Point prc_role to prc_person receiving role Add the * role to the set of roles in receiving prc_person Remove role from prc person losing role */ protected void updateCalculatedPersonsOnMoveOfSor( final Person toPerson, final Person fromPerson, final SorPerson sorPerson) { Assert.notNull(toPerson, "toPerson cannot be null"); Assert.notNull(fromPerson, "fromPerson cannot be null"); logger.info("UpdateCalculated: recalculating person data for move."); final List<Role> rolesToDelete = new ArrayList<Role>(); final List<SorRole> sorRoles = new ArrayList<SorRole>(sorPerson.getRoles()); for (final SorRole sorRole : sorRoles) { for (final Role role : fromPerson.getRoles()) { if (sorRole.getId().equals(role.getSorRoleId())) { sorRoleElector.addSorRole(sorRole, toPerson); rolesToDelete.add(role); } } } for (final Role role : rolesToDelete) { sorRoleElector.removeCalculatedRole( fromPerson, role, this.personRepository.getSoRRecordsForPerson(fromPerson)); fromPerson.getRoles().remove(role); } // TODO recalculate names for person receiving role? Anything else? // TODO recalculate names for person losing role? Anything else? // this.personRepository.savePerson(fromPerson); // this.personRepository.savePerson(toPerson); }
/** 基类实现消息监听接口,加上打印metaq监控日志的方法 */ @Override public ConsumeConcurrentlyStatus consumeMessage( List<MessageExt> msgs, ConsumeConcurrentlyContext context) { long startTime = System.currentTimeMillis(); logger.info("receive_message:{}", msgs.toString()); if (msgs == null || msgs.size() < 1) { logger.error("receive empty msg!"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } List<Serializable> msgList = new ArrayList<>(); for (MessageExt message : msgs) { msgList.add(decodeMsg(message)); } final int reconsumeTimes = msgs.get(0).getReconsumeTimes(); MsgObj msgObj = new MsgObj(); msgObj.setReconsumeTimes(reconsumeTimes); msgObj.setMsgList(msgList); msgObj.setContext(context); context.setDelayLevelWhenNextConsume(getDelayLevelWhenNextConsume(reconsumeTimes)); ConsumeConcurrentlyStatus status = doConsumeMessage(msgObj); logger.info( "ConsumeConcurrentlyStatus:{}|cost:{}", status, System.currentTimeMillis() - startTime); return status; }
public static FileDesc loadFile(Path root, Path file, int blocSize) throws NoSuchAlgorithmException, FileNotFoundException, IOException { MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest fileMd = MessageDigest.getInstance("SHA-512"); FileDesc desc = new FileDesc(file.toString(), null, null); List<Bloc> list = new ArrayList<Bloc>(); try (FileInputStream fis = new FileInputStream(root.resolve(file).toString())) { byte[] buf = new byte[blocSize]; byte[] h; int s; while ((s = fis.read(buf)) != -1) { int c; while (s < buf.length && (c = fis.read()) != -1) buf[s++] = (byte) c; fileMd.update(buf, 0, s); // padding byte p = 0; while (s < buf.length) buf[s++] = ++p; h = md.digest(buf); Bloc bloc = new Bloc(RollingChecksum.compute(buf), new Hash(h)); list.add(bloc); } h = fileMd.digest(); desc.fileHash = new Hash(h); desc.blocs = list.toArray(new Bloc[0]); } return desc; }
/** @return matching bloc B bloc -> A bloc */ public static Map<Integer, Integer> diff(FileDesc a, FileDesc b) { Map<Integer, List<IndexedHash>> blocA = new HashMap<Integer, List<IndexedHash>>(); int i = 0; for (Bloc bloc : a.blocs) { List<IndexedHash> l = blocA.get(bloc.roll); if (l == null) { l = new ArrayList<IndexedHash>(); blocA.put(bloc.roll, l); } l.add(new IndexedHash(i++, bloc.hash)); } Map<Integer, Integer> map = new HashMap<Integer, Integer>(); loop: for (i = 0; i < b.blocs.length; i++) { Bloc blocB = b.blocs[i]; List<IndexedHash> list = blocA.get(blocB.roll); if (list != null) { for (IndexedHash bloc : list) { if (blocB.hash.equals(bloc.h)) { map.put(i, bloc.i); continue loop; } } } } return map; }
protected List<PersonMatch> createMatches(final List<Person> people) { final List<PersonMatch> personMatches = new ArrayList<PersonMatch>(); for (final Person person : people) { final PersonMatch p = new PersonMatchImpl(person, 50, new ArrayList<FieldMatch>()); personMatches.add(p); } return personMatches; }
protected void addOrReplace(ParsedMapping parsedMapping) { MappingKey key = new MappingKey(parsedMapping); for (int i = 0; i < mappings.size(); i++) { if (key.equals(new MappingKey(mappings.get(i)))) { logger.warn("{}\nis replaced with\n{}", mappings.get(i), parsedMapping); mappings.set(i, parsedMapping); return; } } logger.debug("Parsed {}", parsedMapping); mappings.add(parsedMapping); }
protected List<MappingWithDirection> findApplicable(MappingKey key) { ArrayList<MappingWithDirection> result = new ArrayList<MappingWithDirection>(); for (ParsedMapping pm : mappings) { if ((pm.mappingCase == null && key.mappingCase == null) ^ (pm.mappingCase != null && pm.mappingCase.equals(key.mappingCase))) { if (pm.sideA.isAssignableFrom(key.source) && pm.sideB.isAssignableFrom(key.target)) result.add(new MappingWithDirection(pm, true)); else if (pm.sideB.isAssignableFrom(key.source) && pm.sideA.isAssignableFrom(key.target)) result.add(new MappingWithDirection(pm, false)); } } if (!result.isEmpty()) { Collections.sort(result, new MappingComparator(key.target)); } else if (automappingEnabled) { logger.info( "Could not find applicable mappings between {} and {}. A mapping will be created using automapping facility", key.source.getName(), key.target.getName()); ParsedMapping pm = new Mapping(key.source, key.target, this).automap().parse(); logger.debug("Automatically created {}", pm); mappings.add(pm); result.add(new MappingWithDirection(pm, true)); } else logger.warn( "Could not find applicable mappings between {} and {}!", key.source.getName(), key.target.getName()); return result; }
@Test public void testFindAllAlbumsByOwner() throws Exception { Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION); album.modifyUser(user); Album createdAlbum = repository.create(album); // Execute List<Album> foundAlbums = repository.findAllByOwner(user.getUserId()); // Verify em.flush(); em.clear(); Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId()); assertEquals(1, foundAlbums.size()); assertTrue(foundAlbums.contains(actualAlbum)); }
private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } final List<String> encryptedSegments = (List<String>) encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { final String encryptedUrlString = (String) encryptedSegments.get(0); if (Strings.isEmpty((CharSequence) encryptedUrlString)) { return null; } final String decryptedUrl = this.getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } final Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); final int originalNumberOfSegments = originalUrl.getSegments().size(); final int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo; for (segNo = 1; segNo < encryptedNumberOfSegments; ++segNo) { if (segNo > originalNumberOfSegments) { break; } final String next = generator.next(); final String encryptedSegment = (String) encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } while (segNo < encryptedNumberOfSegments) { url.getSegments().add(encryptedUrl.getSegments().get(segNo)); ++segNo; } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { CryptoMapper.log.error("Error decrypting URL", e); url = null; } return url; }
/** * By default, this will always attempt to call {@link System#exit(int)} at the end of running * tests, exiting with 0 if all tests pass, 4 if any units have failed, and 5 if any unit failed * catastrophically (i.e. the entire case was not completed). This behavior and/or those values * can be overridden by overriding the {@link #succeeded()}, {@link #failed()}, and {@link * #aborted()} methods, respectively. */ public synchronized void run() { List<Unit> $units = getUnits(); // list is assumed immutable on pain of death or idiocy $numUnits = $units.size(); $numUnitsRun = 0; $numUnitsPassed = 0; $numUnitsFailed = 0; for (int $i = 0; $i < $units.size(); $i++) { Unit $unit = $units.get($i); if ($unit == null) continue; try { resetFailures(); $log.info("TEST UNIT " + $unit.getName() + " STARTING..."); $numUnitsRun++; $unit.call(); if ($unit.expectExceptionType() != null) { $numUnitsFailed++; $log.error("EXPECTED EXCEPTION; TEST CASE ABORTED."); aborted(); } if ($unitFailures == 0) { $numUnitsPassed++; $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n"); } else { $numUnitsFailed++; $log.info( "TEST UNIT " + $unit.getName() + " FAILED (WITH " + $unitFailures + " FAILURES)!\n"); } } catch (AssertionFatal $e) { $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } catch (AssertionFailed $e) { $numUnitsFailed++; $log.error("TEST UNIT " + $unit.getName() + " ABORTED.", $e); } catch (Throwable $e) { if ($unit.expectExceptionType() != null) { // some kind of exception was expected. if ($unit.expectExceptionType().isAssignableFrom($e.getClass())) { // and it was this kind that was expected, so this is good. $numUnitsPassed++; $unit.assertInstanceOf( $unit.expectExceptionType(), $e); // generates a normal confirmation message $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n"); } else { // and it wasn't this kind. this represents fatal failure. $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } } else { // no exception was expected. any exception represents fatal failure. $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } } } if ($numUnitsFailed > 0) failed(); else succeeded(); }
protected Person recalculatePersonBiodemInfo( final Person person, final SorPerson sorPerson, final RecalculationType recalculationType, boolean mistake) { final List<SorPerson> sorPersons = this.personRepository.getSoRRecordsForPerson(person); logger.info("recalculatePersonBiodemInfo: start"); if (recalculationType == RecalculationType.ADD || (recalculationType == RecalculationType.DELETE && !mistake)) { sorPersons.add(sorPerson); } copySorNamesToPerson(person, sorPersons); final Date birthDate = this.birthDateFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final String gender = this.genderFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final SorName preferredName = this.preferredNameFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final SorName officialName = this.officialNameFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final EmailAddress emailAddress = this.preferredContactEmailAddressFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final Phone phone = this.preferredContactPhoneNumberFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final Map<String, String> attributes = this.attributesElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final SorDisclosureSettings disclosure = this.disclosureFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); final String ssn = this.ssnFieldElector.elect( sorPerson, sorPersons, recalculationType == RecalculationType.DELETE); Identifier primarySSN = person.getPrimaryIdentifiersByType().get("SSN"); // check if the elector elcted some ssn and person does have previous ssn assigned to it if (!org.apache.commons.lang.StringUtils.isEmpty(ssn) && primarySSN != null) { try { this.identifierChangeService.change(person.getPrimaryIdentifiersByType().get("SSN"), ssn); } catch (IllegalArgumentException e) { logger.debug(e.getStackTrace().toString()); } // all other exception should be propogated } person.setDateOfBirth(birthDate); person.setGender(gender); person.getPreferredContactEmailAddress().update(emailAddress); person.getPreferredContactPhoneNumber().update(phone); person.calculateDisclosureSettings(disclosure); person.setAttributes(attributes); String affiliation = ""; Type affiliationType = null; if (disclosure != null) { logger.info( "after person.calculateDisclosureSettings, disclosure code : " + disclosure.getDisclosureCode()); } else { logger.info("Disclosure is null"); } List<SorRole> sorroles = sorPerson.getRoles(); for (SorRole role : sorroles) { if (role != null) { logger.info("Role = " + role.getTitle()); if (role.getAffiliationType() != null) { logger.info("Role desc= " + role.getAffiliationType().getDescription()); affiliation = role.getAffiliationType().getDescription(); if (person.getDisclosureSettings() != null) { logger.info("recalculating disclosure setting 1..."); // person.getDisclosureSettings().recalculate(this.strategyRepository.getDisclosureRecalculationStrategy()); person .getDisclosureSettings() .recalculate( this.strategyRepository.getDisclosureRecalculationStrategy(), affiliation, referenceRepository); } } } } // SSN election is happening in the ssn identifier assigner. boolean preferred = false; boolean official = false; for (final Name name : person.getNames()) { if (!preferred && name.sameAs(preferredName)) { name.setPreferredName(true); preferred = true; } if (!official && name.sameAs(officialName)) { name.setOfficialName(true); official = true; } if (official && preferred) { break; } } logger.info("recalculatePersonBiodemInfo: end"); // return this.personRepository.savePerson(person); return person; }