Checks, if a already exists a corpus with the same name of the top level
corpus in the corpus.tab file. If this is the case an Exception is thrown
and the import is aborted.

@throws
annis.administration.DefaultAdministrationDao.ConflictingCorpusException
358912
private void checkTopLevelCorpus() throws ConflictingCorpusException
  {
    String corpusName = getTopLevelCorpusFromTmpArea();
    if (existConflictingTopLevelCorpus(corpusName))
    {
      String msg
        = "There already exists a top level corpus with the name: " + corpusName;
      throw new ConflictingCorpusException(msg);
    }
  }
1334237
private boolean ensureHiveTableExistenceBeforeAlternation(String tableName, String dbName, IMetaStoreClient client,
      Table table, HiveSpec spec) throws TException{
    try (AutoCloseableLock lock = this.locks.getTableLock(dbName, tableName)) {
      try {
        try (Timer.Context context = this.metricContext.timer(CREATE_HIVE_TABLE).time()) {
          client.createTable(getTableWithCreateTimeNow(table));
          log.info(String.format("Created Hive table %s in db %s", tableName, dbName));
          return true;
        } catch (AlreadyExistsException e) {
        }
      }catch (TException e) {
        log.error(
            String.format("Unable to create Hive table %s in db %s: " + e.getMessage(), tableName, dbName), e);
        throw e;
      }

      log.info("Table {} already exists in db {}.", tableName, dbName);
      try {
        HiveTable existingTable;
        try (Timer.Context context = this.metricContext.timer(GET_HIVE_TABLE).time()) {
          existingTable = HiveMetaStoreUtils.getHiveTable(client.getTable(dbName, tableName));
        }
        if (needToUpdateTable(existingTable, spec.getTable())) {
          try (Timer.Context context = this.metricContext.timer(ALTER_TABLE).time()) {
            client.alter_table(dbName, tableName, getNewTblByMergingExistingTblProps(table, existingTable));
          }
          log.info(String.format("updated Hive table %s in db %s", tableName, dbName));
        }
      } catch (TException e2) {
        log.error(
            String.format("Unable to create or alter Hive table %s in db %s: " + e2.getMessage(), tableName, dbName),
            e2);
        throw e2;
      }
      // When the logic up to here it means table already existed in db and alteration happen. Return false.
      return false;
    }
  }
1364029
public function fileExists()
    {
        if (!$this->hasRequestParameter('uri') || !$this->hasRequestParameter('path') || !$this->hasRequestParameter('lang')) {
            throw new common_exception_MissingParameter();
        }

        $item = $this->getResource($this->getRequestParameter('uri'));
        $itemLang = $this->getRequestParameter('lang');

        try {
            $resolver = new ItemMediaResolver($item, $itemLang);
            $asset = $resolver->resolve($this->getRequestParameter('path'));
            $asset->getMediaSource()->getFileInfo($asset->getMediaIdentifier());
            $found = true;
        } catch (tao_models_classes_FileNotFoundException $exception) {
            $found = false;
        }
        return $this->returnJson(array(
            'exists' => $found
        ));
    }
641159
public static boolean checkCompatibleModuleResources(CmsModule installedModule, CmsModule newModule) {

        if (!(installedModule.hasOnlySystemAndSharedResources() && newModule.hasOnlySystemAndSharedResources())) {
            String oldSite = installedModule.getSite();
            String newSite = newModule.getSite();
            if (!((oldSite != null) && (newSite != null) && CmsStringUtil.comparePaths(oldSite, newSite))) {
                return false;
            }

        }
        for (String oldModRes : installedModule.getResources()) {
            for (String newModRes : newModule.getResources()) {
                if (CmsStringUtil.isProperPrefixPath(oldModRes, newModRes)) {
                    return false;
                }
            }
        }
        return true;

    }
1021041
def add_name(self, name, lang=None):
        
        try:
            assert (lang, name) not in self.get_names()
        except Exception as e:
            # TODO: raise a custom exception
            logger.warning("Duplicate name detected while adding \"%s (lang=%s)\""%(name, lang))
            return False
        newlabel = Literal(name, lang=lang) if lang is not None else \
            Literal(name)
        name = [
            id
            for id in self.ecrm_P1_is_identified_by
            if id.uri == surf.ns.EFRBROO['F12_Name']
        ][0]
        try:
            name.rdfs_label.append(newlabel)
            name.update()
            return True
        except Exception as e:
            raise e
1329500
def collect_conflicts_between_fields_and_fragment(
    context: ValidationContext,
    conflicts: List[Conflict],
    cached_fields_and_fragment_names: Dict,
    compared_fragments: Set[str],
    compared_fragment_pairs: "PairSet",
    are_mutually_exclusive: bool,
    field_map: NodeAndDefCollection,
    fragment_name: str,
) -> None:
    
    # Memoize so a fragment is not compared for conflicts more than once.
    if fragment_name in compared_fragments:
        return
    compared_fragments.add(fragment_name)

    fragment = context.get_fragment(fragment_name)
    if not fragment:
        return None

    field_map2, fragment_names2 = get_referenced_fields_and_fragment_names(
        context, cached_fields_and_fragment_names, fragment
    )

    # Do not compare a fragment's fieldMap to itself.
    if field_map is field_map2:
        return

    # (D) First collect any conflicts between the provided collection of fields and the
    # collection of fields represented by the given fragment.
    collect_conflicts_between(
        context,
        conflicts,
        cached_fields_and_fragment_names,
        compared_fragment_pairs,
        are_mutually_exclusive,
        field_map,
        field_map2,
    )

    # (E) Then collect any conflicts between the provided collection of fields and any
    # fragment names found in the given fragment.
    for fragment_name2 in fragment_names2:
        collect_conflicts_between_fields_and_fragment(
            context,
            conflicts,
            cached_fields_and_fragment_names,
            compared_fragments,
            compared_fragment_pairs,
            are_mutually_exclusive,
            field_map,
            fragment_name2,
        )
562663
protected boolean existConflictingTopLevelCorpus(String topLevelCorpusName)
  {
    String sql = "SELECT count(name) as amount FROM corpus WHERE top_level=true AND name='"
      + topLevelCorpusName + "'";
    Integer numberOfCorpora = getJdbcTemplate().query(sql,
      new ResultSetExtractor<Integer>()
      {
        @Override
        public Integer extractData(ResultSet rs) throws SQLException,
        DataAccessException
        {
          if (rs.next())
          {
            return rs.getInt("amount");
          }
          else
          {
            return 0;
          }
        }
      });

    return numberOfCorpora > 0;
  }
1204164
public B importContext(AbstractContext context, boolean overwriteDuplicates){
        for (Map.Entry<String, Object> en : context.data.entrySet()) {
            if (overwriteDuplicates) {
                this.data.put(en.getKey(), en.getValue());
            }else{
                this.data.putIfAbsent(en.getKey(), en.getValue());
            }
        }
        return (B) this;
    }
580285
private boolean existsStrongerInColumn(INode source, INode target) {
        boolean result = false;

        char current = defautlMappings.getRelation(source, target);

        //compare with the other relations in the column
        for (INode i : defautlMappings.getSourceContext().getNodesList()) {
            if (i != source && defautlMappings.getRelation(i, target) != IMappingElement.IDK
                    && isPrecedent(defautlMappings.getRelation(i, target), current)) {
                result = true;
                break;
            }
        }

        return result;
    }
605754
private boolean checkFilesExists(String[] requiredFiles, File childResource) {

        File setupFile = null;
        boolean hasMissingSetupFiles = false;

        for (int j = 0; j < requiredFiles.length; j++) {
            setupFile = new File(childResource.getPath() + File.separatorChar + requiredFiles[j]);

            if (!setupFile.exists() || !setupFile.isFile() || !setupFile.canRead()) {
                hasMissingSetupFiles = true;
                System.err.println(
                    "[" + getClass().getName() + "] missing or unreadable database setup file: " + setupFile.getPath());
                break;
            }

            if (!hasMissingSetupFiles) {
                return true;
            }
        }
        return false;
    }
881733
private boolean isDuplicateName(String name) {
		if (this.existingNames != null) {
			final String newName = Strings.nullToEmpty(name);
			for (final String existingName : this.existingNames) {
				if (newName.equals(existingName)) {
					return true;
				}
			}
		}
		return false;
	}
1271943
public static void checkPersistenceXMLValidity ()
  {
    // Check if all persistence.xml files contain valid classes!
    try
    {
      int nCount = 0;
      final Enumeration <URL> aEnum = ClassLoaderHelper.getResources (ClassLoaderHelper.getDefaultClassLoader (),
                                                                      PATH_PERSISTENCE_XML);
      while (aEnum.hasMoreElements ())
      {
        nCount++;
        final URL aURL = aEnum.nextElement ();
        final IMicroDocument aDoc = MicroReader.readMicroXML (new URLResource (aURL));
        if (aDoc == null || aDoc.getDocumentElement () == null)
          throw new IllegalStateException ("No XML file: " + aURL);
        for (final IMicroElement ePU : aDoc.getDocumentElement ().getAllChildElements (PERSISTENCE_NAMESPACE_URI,
                                                                                       "persistence-unit"))
          for (final IMicroElement eClass : ePU.getAllChildElements (PERSISTENCE_NAMESPACE_URI, "class"))
          {
            final String sClass = eClass.getTextContent ();
            if (StringHelper.hasNoTextAfterTrim (sClass))
              throw new IllegalStateException ("Persistence file " + aURL + ": class name is missing!");
            GenericReflection.getClassFromName (sClass.trim ());
          }
      }
      LOGGER.info ("All " + PATH_PERSISTENCE_XML + " files are valid (count=" + nCount + ")");
    }
    catch (final IOException ex)
    {
      // From getResources
      throw new IllegalStateException ("Failed to read " + PATH_PERSISTENCE_XML + " file", ex);
    }
    catch (final ClassNotFoundException ex)
    {
      // If forName fails
      throw new IllegalStateException ("Failed to resolve class", ex);
    }
  }
1032486
public boolean packageExists(ModuleSymbol msym, Name fullname) {
        Assert.checkNonNull(msym);
        return lookupPackage(msym, fullname).exists();
    }
1267184
private void validateDepDefinitionUniqueness(final List<TriggerDependencyBean> dependencies) {
    for (int i = 0; i < dependencies.size(); i++) {
      for (int j = i + 1; j < dependencies.size(); j++) {
        final boolean duplicateDepDefFound =
            dependencies.get(i).getType().equals(dependencies.get(j)
                .getType()) && dependencies.get(i).getParams()
                .equals(dependencies.get(j).getParams());
        Preconditions.checkArgument(!duplicateDepDefFound, String.format("duplicate dependency"
                + "config %s found, dependency config should be unique",
            dependencies.get(i).getName()));
      }
    }
  }
593299
public boolean hasResource(String name, Locale locale) {
        name = UrlUtils.cleanName(name);
        locale = cleanLocale(locale);
        return stringLoader.exists(name, locale) || loader.exists(name, locale);
    }
325299
public boolean equalsOnlyNames(NodeSchema otherSchema) {
        if (otherSchema == null) {
            return false;
        }

        if (otherSchema.size() != size()) {
            return false;
        }

        for (int colIndex = 0; colIndex < size(); colIndex++ ) {
            SchemaColumn col1 = otherSchema.getColumn(colIndex);
            SchemaColumn col2 = m_columns.get(colIndex);
            if (col1.compareNames(col2) != 0) {
                return false;
            }
        }

        return true;
    }
476528
protected final boolean entityExists(final String entityName) {
        final Set<EntityType<?>> entityTypes = getEm().getMetamodel().getEntities();
        for (final EntityType<?> entityType : entityTypes) {
            if (entityType.getName().equals(entityName)) {
                return true;
            }
        }
        return false;
    }