private static void logPersistence(AnnotatedObject<?,?> ao) { if (log.isDebugEnabled()) { log.debug("\t\t\tPersisted with AC: " + ao.getAc()); if (!ao.getXrefs().isEmpty()) { log.debug("\t\t\tXrefs: " + ao.getXrefs().size()); for (Xref xref : ao.getXrefs()) { log.debug("\t\t\t\t"+xref); } } if (!ao.getAliases().isEmpty()) { log.debug("\t\t\tAliases: " + ao.getAliases().size()); for (Alias alias: ao.getAliases()) { log.debug("\t\t\t\t"+alias); } } if (!ao.getAnnotations().isEmpty()) { log.debug("\t\t\tAnnotations: " + ao.getAnnotations().size()); for (Annotation annot: ao.getAnnotations()) { log.debug("\t\t\t\t"+annot); } } } }
if ( annotatedObject.getAc() != null & ac != null ) { return ac.equals( annotatedObject.getAc() ); if ( !shortLabel.equals( annotatedObject.getShortLabel() ) ) { return false; if ( annotatedObject.getShortLabel() != null ) { return false; if ( !fullName.equals( annotatedObject.getFullName() ) ) { return false; if ( annotatedObject.getFullName() != null ) { return false; return CollectionUtils.isEqualCollection( getXrefs(), annotatedObject.getXrefs() );
protected void traverseAnnotatedObjectCommon(AnnotatedObject ao, IntactVisitor ... visitors) { traverse(ao.getAnnotations(), visitors); traverse(ao.getAliases(), visitors); traverse(ao.getXrefs(), visitors); // check if this element has been traversed already, to avoid cyclic recursion if (recursionChecker.isAlreadyTraversed(ao)) { return; } traverse(ao.getOwner(), visitors); }
public SimplifiedAnnotatedObject( AnnotatedObject annotatedObject ) { this.ac = annotatedObject.getAc(); this.shortLabel = annotatedObject.getShortLabel(); this.created = annotatedObject.getCreated(); }
protected boolean updateCommonAttributes(T candidateObject, T objectToBeUpdated) throws PersisterException { for (Annotation annotation : candidateObject.getAnnotations()) { objectToBeUpdated.addAnnotation(annotation); } saveOrUpdateAttributes(objectToBeUpdated); return true; } }
public AnnotatedObjectStatsUnit(AnnotatedObject ao) { this.shortLabel = ao.getShortLabel(); this.ac = ao.getAc(); this.type = CgLibUtil.removeCglibEnhanced(ao.getClass()); }
clone.setOwner(clone(ao.getOwner())); clone.setShortLabel(ao.getShortLabel()); clone.setFullName(ao.getFullName()); String ac = ao.getAc(); if (isCollectionClonable(ao.getAnnotations())) { Collection<Annotation> annotations = IntactCore.ensureInitializedAnnotations(ao); clone.addAnnotation(clone(annotation)); if (isCollectionClonable(ao.getAliases())) { Collection<? extends Alias> aliases = IntactCore.ensureInitializedAliases(ao); clone.addAlias(clone(alias)); if (isCollectionClonable(ao.getXrefs())) { Collection<? extends Xref> refs = IntactCore.ensureInitializedXrefs(ao); clone.addXref(clone(xref));
protected <X extends Xref, A extends Alias> void copyAnotatedObjectCommons( AnnotatedObject<X, A> source, AnnotatedObject<X, A> target ) { // if the source does not have an AC, we should not update the target shortLabel, fullName and owner // as it does not make much sense //if (source.getAc() != null) { copyProperty(source, "shortLabel", target); copyProperty(source, "fullName", target); copyProperty(source, "owner", target); //} copyXrefCollection( source.getXrefs(), target.getXrefs() ); copyAliasCollection( source.getAliases(), target.getAliases(), source, target ); copyAnnotationCollection( source.getAnnotations(), target.getAnnotations() ); }
Institution owner = intactObject.getOwner(); intactObject.setOwner(institutionPersister.syncIfTransient(owner)); for (Xref xref : intactObject.getXrefs()) { CvDatabase cvDb = (CvDatabase) cvPersister.syncIfTransient(xref.getCvDatabase()); xref.setCvDatabase(cvDb); xref.setOwner(institutionPersister.syncIfTransient(xref.getOwner())); for (Alias alias : intactObject.getAliases()) { CvAliasType cvAliasType = alias.getCvAliasType(); alias.setOwner(institutionPersister.syncIfTransient(alias.getOwner())); for (Annotation annotation : intactObject.getAnnotations()) { CvTopic cvTopic = annotation.getCvTopic(); throw new IntactException("Exception syncing attributes of: "+intactObject.getShortLabel()+" ("+intactObject.getAc()+")", t);
private <T extends AnnotatedObject> void copyAnnotatedObjectAttributeAcs( T source, T target ) { if (IntactCore.isInitialized(target.getXrefs())) { for ( Iterator itXrefTarget = target.getXrefs().iterator(); itXrefTarget.hasNext(); ) { Xref targetXref = (Xref) itXrefTarget.next(); for ( Iterator itXrefSrc = source.getXrefs().iterator(); itXrefSrc.hasNext(); ) { Xref sourceXref = ( Xref ) itXrefSrc.next(); target.addXref( xref ); if (IntactCore.isInitialized(target.getAliases())) { for ( Iterator itAliasTarget = target.getAliases().iterator(); itAliasTarget.hasNext(); ) { Alias targetAlias = (Alias) itAliasTarget.next(); for ( Iterator itAliasSrc = source.getAliases().iterator(); itAliasSrc.hasNext(); ) { Alias sourceAlias = ( Alias ) itAliasSrc.next(); target.addAlias( alias ); if (IntactCore.isInitialized(target.getAnnotations())) { for ( Iterator itAnnotTarget = target.getAnnotations().iterator(); itAnnotTarget.hasNext(); ) { Annotation targetAnnot = (Annotation) itAnnotTarget.next(); for ( Iterator itAnnotSrc = source.getAnnotations().iterator(); itAnnotSrc.hasNext(); ) { Annotation sourceAnnot = ( Annotation ) itAnnotSrc.next(); target.addAnnotation( annotation );
private static List<SearchItem> searchItemsForAnnotatedObject( AnnotatedObject<? extends Xref, ? extends Alias> ao, boolean includeAliases ) { List<SearchItem> searchItems = new ArrayList<SearchItem>(); searchItems.add( new SearchItem( ao.getAc(), ao.getAc(), ao.getClass().getName(), "ac" ) ); searchItems.add( new SearchItem( ao.getAc(), ao.getShortLabel(), ao.getClass().getName(), "shortlabel" ) ); if ( ao.getFullName() != null ) { searchItems.add( new SearchItem( ao.getAc(), ao.getFullName(), ao.getClass().getName(), "fullname" ) ); } if ( includeAliases ) { for ( Alias alias : ao.getAliases() ) { if ( alias.getCvAliasType() != null ) { searchItems.add( new SearchItem( ao.getAc(), alias.getName(), ao.getClass().getName(), alias.getCvAliasType().getShortLabel() ) ); } else { log.warn( "Couldn't insert SearchItem for Alias, as it cvAliasType is null: " + alias.getName() ); } } } return searchItems; }
if ( ao.getAc() == null || ao.getAc().length() == 0) { if (log.isTraceEnabled()) log.trace("New "+ao.getClass().getSimpleName()+": "+ao.getShortLabel()+" - Decision: PERSIST"); if (log.isTraceEnabled()) log.trace("New (but found in database: "+ ac +") "+ao.getClass().getSimpleName()+": "+ao.getShortLabel()+" - Decision: UPDATE"); ao.setAc(managedObject.getAc()); if (log.isTraceEnabled()) log.trace("New (but found in database: "+ ac +") "+ao.getClass().getSimpleName()+": "+ao.getShortLabel()+" - Decision: IGNORE"); if (statisticsEnabled) statistics.addDuplicate(ao); ao.setAc(ac); if (log.isTraceEnabled()) log.trace("Transient "+ao.getClass().getSimpleName()+": "+ao.getAc()+" "+ao.getShortLabel()+" - Decision: SYNCHRONIZE-REFRESH"); String ac = ao.getAc(); throw new IllegalStateException(ao.getClass().getSimpleName()+" is transient, but no object with the same AC could be found in database: "+ao.getAc()+" ("+ao.getShortLabel()+")"); copied = entityStateCopier.copy( ao, managedObject); } catch (Exception e) { throw new PersisterException("Problem copying state to managed object of type "+ao.getClass().getSimpleName()+" and AC "+ao.getAc()+", from object: "+ao, e); ao.setAc(ac); copyAnnotatedObjectAttributeAcs(managedObject, ao); } catch (Exception e) { throw new PersisterException("Problem copying ACs from managed object of type "+ao.getClass().getSimpleName()+" and AC "+ao.getAc()+", to object: "+ao, e);
@Transient public String getParentAc() { if ( parent != null ) { parentAc = parent.getAc(); } return parentAc; }
public static Collection<Annotation> getPublicAnnotations(final AnnotatedObject<?, ?> annotatedObject) { final Collection<Annotation> publicAnnotations = new ArrayList<Annotation>(annotatedObject.getAnnotations().size()); final Iterator<Annotation> i = IntactCore.ensureInitializedAnnotations(annotatedObject).iterator(); while (i.hasNext()) { Annotation annotation = i.next(); if (isCvTopicPublic(annotation.getCvTopic())) { publicAnnotations.add(annotation); } } return publicAnnotations; }
protected static Institution getInstitution(AnnotatedObject ao) { if (ao instanceof Institution) { return (Institution)ao; } else { return ao.getOwner(); } }
/** * Retrieves the annotations from an AnnotatedObject, initializing them if necessary. * * @param ao The annotated object instance with possibly non-initialized annotations * @return The returned annotations are ensured to be initialized * @since 2.4.0 */ public static Collection<Annotation> ensureInitializedAnnotations(AnnotatedObject ao) { Collection<Annotation> annotations; if (IntactCore.isInitialized(ao.getAnnotations())) { annotations = ao.getAnnotations(); } else { annotations = IntactContext.getCurrentInstance().getDaoFactory().getAnnotationDao().getByParentAc(ao.getClass(), ao.getAc()); } return annotations; }
protected static void populateNames( AnnotatedObject<?, ?> annotatedObject, NamesContainer namesContainer ) { Names names = namesContainer.getNames(); if ( names == null ) { names = new Names(); } String shortLabel = annotatedObject.getShortLabel(); String fullName = annotatedObject.getFullName(); names.setShortLabel( shortLabel ); names.setFullName( fullName ); if ( !ConverterContext.getInstance().getInteractorConfig().isExcludeInteractorAliases() ) { AliasConverter aliasConverter = new AliasConverter( annotatedObject.getOwner(), AnnotatedObjectUtils.getAliasClassType( annotatedObject.getClass() ) ); for ( Alias alias : IntactCore.ensureInitializedAliases(annotatedObject)) { names.getAliases().add( aliasConverter.intactToPsi( alias ) ); } } namesContainer.setNames( names ); }
/** * Returns the list of labels for the annotated objects provided * * @param intactObjects list of annotated objects * * @return a list of labels */ public static List<String> labelList( Collection<? extends AnnotatedObject> intactObjects ) { List<String> labels = new ArrayList<String>( intactObjects.size() ); for ( AnnotatedObject io : intactObjects ) { labels.add( io.getShortLabel() ); } return labels; }
public static void populateNames( AnnotatedObject<?, ?> annotatedObject, NamesContainer namesContainer, AliasConverter aliasConverter ) { Names names = namesContainer.getNames(); if ( names == null ) { names = new Names(); } String shortLabel = annotatedObject.getShortLabel(); String fullName = annotatedObject.getFullName(); names.setShortLabel( shortLabel ); names.setFullName( fullName ); if ( !ConverterContext.getInstance().getInteractorConfig().isExcludeInteractorAliases() ) { Collection<? extends Alias> aliases; if (aliasConverter.isCheckInitializedCollections()){ aliases = IntactCore.ensureInitializedAliases(annotatedObject); } else { aliases = annotatedObject.getAliases(); } for ( Alias alias : aliases) { names.getAliases().add( aliasConverter.intactToPsi( alias ) ); } } namesContainer.setNames( names ); }
/** * Retrieves the xrefs from an AnnotatedObject, initializing them if necessary. * * @param ao The annotated object instance with possibly non-initialized xrefs * @return The returned xrefs are ensured to be initialized * @since 2.4.0 */ public static Collection<? extends Xref> ensureInitializedXrefs(AnnotatedObject<?, ?> ao) { Collection<? extends Xref> xrefs; if (IntactCore.isInitialized(ao.getXrefs())) { xrefs = ao.getXrefs(); } else { xrefs = IntactContext.getCurrentInstance().getDaoFactory().getXrefDao(AnnotatedObjectUtils.getXrefClassType(ao.getClass())) .getByParentAc(ao.getAc()); } return xrefs; }