Gets the GFSInputFile from entity.

@param gfs
the gfs
@param m
the m
@param entity
the entity
@param kunderaMetadata
the kundera metadata
@return the GFS iuput file from entity
165414
public GridFSInputFile getGFSInputFileFromEntity(GridFS gfs, EntityMetadata m, Object entity,
            KunderaMetadata kunderaMetadata, boolean isUpdate)
    {
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(m.getPersistenceUnit());
        EntityType entityType = metaModel.entity(m.getEntityClazz());
        GridFSInputFile gridFSInputFile = null;

        DBObject gfsMetadata = new BasicDBObject();

        Set<Attribute> columns = entityType.getAttributes();
        for (Attribute column : columns)
        {
            boolean isLob = ((Field) column.getJavaMember()).getAnnotation(Lob.class) != null;
            if (isLob)
            {
                gridFSInputFile = createGFSInputFile(gfs, entity, (Field) column.getJavaMember());
                gridFSInputFile.setFilename(column.getName());
            }
            else
            {
                if (isUpdate && column.getName().equals(m.getIdAttribute().getName()))
                {
                    gfsMetadata.put(((AbstractAttribute) column).getJPAColumnName(), new ObjectId());
                }
                else
                    DocumentObjectMapper.extractFieldValue(entity, gfsMetadata, column);
            }
        }
        gridFSInputFile.setMetaData(gfsMetadata);
        return gridFSInputFile;
    }
496938
@Override
    protected List populateEntities(EntityMetadata m, Client client)
    {
        if (kunderaQuery.isNative())
        {
            return ((CouchbaseClient) client).executeNativeQuery(getJPAQuery(), m);
        }
        else
        {
            MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                    .getMetamodel(m.getPersistenceUnit());
            EntityType entityType = metaModel.entity(m.getEntityClazz());
            JPQLExpression jpqlExp = kunderaQuery.getJpqlExpression();
            List<String> selectColumns = KunderaQueryUtils.getSelectColumns(jpqlExp);
            AsPath asPath;
            if (selectColumns.isEmpty())
            {
                asPath = select(CouchbaseConstants.STAR).from(i(m.getSchema()));
            }
            else
            {
                asPath = select(selectColumns.toArray(new String[selectColumns.size()])).from(i(m.getSchema()));
            }
            Statement statement;

            if (KunderaQueryUtils.hasWhereClause(jpqlExp))
            {
                WhereClause whereClause = KunderaQueryUtils.getWhereClause(jpqlExp);
                Expression whereExp = whereClause.getConditionalExpression();

                if (whereExp instanceof ComparisonExpression)
                {
                    String left = ((ComparisonExpression) whereExp).getLeftExpression().toActualText();
                    String right = ((ComparisonExpression) whereExp).getRightExpression().toActualText();
                    if (right.startsWith(CouchbaseConstants.POSITIONAL_PREFIX)
                            || right.startsWith(CouchbaseConstants.PARAMETERIZED_PREFIX))
                    {
                        right = kunderaQuery.getParametersMap().get(right) + "";
                    }
                    Attribute attribute = entityType.getAttribute(left.split(CouchbaseConstants.DOT_REGEX)[1]);

                    statement = addWhereCondition(asPath, ((ComparisonExpression) whereExp).getActualIdentifier(),
                            ((AbstractAttribute) attribute).getJPAColumnName(), right, m.getTableName());
                }

            }
            else
            {
                asPath.where(x(CouchbaseConstants.KUNDERA_ENTITY).eq(x("'" + m.getTableName() + "'")));
            }

            statement = asPath;
            return ((CouchbaseClient) client).executeQuery(statement, m);
        }
    }
518324
private byte[] getUploadFileContent(RequestElements requestElements) throws FMSException {
		Attachable attachable = (Attachable) requestElements.getEntity();
		InputStream docContent = requestElements.getUploadRequestElements().getDocContent();
		
		// gets the mime value form the filename
		String mime = getMime(attachable.getFileName(), ".");
		// if null then gets the mime value from content-type of the file
		mime = (mime != null) ? mime : getMime(attachable.getContentType(), "/");
		if (isImageType(mime)) {
			return getImageContent(docContent, mime);
		} else {
			return getContent(docContent);
		}
	}
593727
public Map<String, DBObject> getDocumentFromEntity(EntityMetadata m, Object entity, List<RelationHolder> relations,
            final KunderaMetadata kunderaMetadata) throws PropertyAccessException
    {
        Map<String, DBObject> dbObjects = new HashMap<String, DBObject>();

        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(m.getPersistenceUnit());
        EntityType entityType = metaModel.entity(m.getEntityClazz());

        // Populate Row Key
        Object id = PropertyAccessorHelper.getId(entity, m);

        DBObject dbObj = MongoDBUtils.getDBObject(m, m.getTableName(), dbObjects, metaModel, id);

        // dbObjects.put(m.getTableName(), dbObj);

        // Populate columns
        Set<Attribute> columns = entityType.getAttributes();
        for (Attribute column : columns)
        {
            // String tableName = ((AbstractAttribute) column).getTableName() !=
            // null ? ((AbstractAttribute) column)
            // .getTableName() : m.getTableName();
            // dbObj = MongoDBUtils.getDBObject(m, tableName, dbObjects,
            // metaModel, id);

            if (!column.equals(m.getIdAttribute()))
            {
                try
                {
                    Class javaType = ((AbstractAttribute) column).getBindableJavaType();
                    if (metaModel.isEmbeddable(javaType))
                    {
                        Map<String, DBObject> embeddedObjects = onEmbeddable(column, entity, metaModel, dbObj,
                                m.getTableName());
                        for (String documentName : embeddedObjects.keySet())
                        {
                            DBObject db = dbObjects.get(documentName);
                            if (db == null)
                            {
                                db = MongoDBUtils.getDBObject(m, documentName, dbObjects, metaModel, id);
                            }
                            db.put(((AbstractAttribute) column).getJPAColumnName(), embeddedObjects.get(documentName));
                            dbObjects.put(documentName, db);

                        }
                    }
                    else if (!column.isAssociation())
                    {
                        DocumentObjectMapper.extractFieldValue(entity, dbObj, column);
                    }
                }
                catch (PropertyAccessException paex)
                {
                    log.error("Can't access property " + column.getName());
                }
            }
            // dbObjects.put(tableName, dbObj);
        }
        if (relations != null)
        {
            dbObj = dbObjects.get(m.getTableName());
            for (RelationHolder rh : relations)
            {
                dbObj.put(rh.getRelationName(),
                        MongoDBUtils.populateValue(rh.getRelationValue(), rh.getRelationValue().getClass()));
            }
            // dbObjects.put(m.getTableName(), dbObj);
        }

        if (((AbstractManagedType) entityType).isInherited())
        {
            dbObj = dbObjects.get(m.getTableName());
            String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn();
            String discrValue = ((AbstractManagedType) entityType).getDiscriminatorValue();

            // No need to check for empty or blank, as considering it as valid
            // name for nosql!
            if (discrColumn != null && discrValue != null)
            {
                dbObj.put(discrColumn, discrValue);
            }
            // dbObjects.put(m.getTableName(), dbObj);
        }
        return dbObjects;
    }
962399
public void get(String remoteFileName,
                    File localFile)
        throws IOException,
               ClientException,
               ServerException {
        if (gSession.transferMode == GridFTPSession.MODE_EBLOCK) {
            DataSink sink =
                new FileRandomIO(new RandomAccessFile(localFile, "rw"));
            get(remoteFileName, sink, null);
        } else {
            super.get(remoteFileName, localFile);
        }
    }
347490
public Map<String, String> getUriVariablesForAddFile(BullhornEntityInfo entityInfo, Integer entityId, FileMeta fileMeta) {
		Map<String, String> uriVariables = fileMeta.getParameterMap();

		String bhRestToken = bullhornApiRest.getBhRestToken();
		uriVariables.put(BH_REST_TOKEN, bhRestToken);
		uriVariables.put(ENTITY_TYPE, entityInfo.getName());
		uriVariables.put(ENTITY_ID, entityId.toString());

		if (fileMeta.getId() != null) {
			uriVariables.put(FILE_ID, fileMeta.getId().toString());
		}

		return uriVariables;
	}
895918
public DataFrame getDataFrame(String query, EntityMetadata m, KunderaQuery kunderaQuery)
    {
        PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata().getPersistenceUnitMetadata(
                persistenceUnit);
        String clientName = puMetadata.getProperty(DATA_CLIENT).toLowerCase();

        SparkDataClient dataClient = SparkDataClientFactory.getDataClient(clientName);
        if (registeredTables.get(m.getTableName()) == null || !registeredTables.get(m.getTableName()))
        {
            dataClient.registerTable(m, this);
            registeredTables.put(m.getTableName(), true);
        }
        // at this level temp table or table should be ready
        DataFrame dataFrame = sqlContext.sql(query);

        return dataFrame;
    }
141929
private void populateGFSEntity(EntityMetadata entityMetadata, List entities, GridFSDBFile gfsDBFile)
    {
        Object entity = instantiateEntity(entityMetadata.getEntityClazz(), null);
        handler.getEntityFromGFSDBFile(entityMetadata.getEntityClazz(), entity, entityMetadata, gfsDBFile,
                kunderaMetadata);
        entities.add(entity);
    }
1092577
private byte[] getBytes(String jpaFieldName, EntityMetadata m, Object value)
    {
        AbstractAttribute idCol = (AbstractAttribute) m.getIdAttribute();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());

        EntityType entity = metaModel.entity(m.getEntityClazz());
        Class fieldClazz = null;
        if (idCol.getName().equals(jpaFieldName))
        {
            Field f = (Field) idCol.getJavaMember();

            if (metaModel.isEmbeddable(idCol.getBindableJavaType()))
            {
                fieldClazz = String.class;
                Map<Attribute, List<Object>> columnValues = new HashMap<Attribute, List<Object>>();
                Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields();
                EmbeddableType embeddable = metaModel.embeddable(m.getIdAttribute().getBindableJavaType());

                StringBuilder compositeKey = new StringBuilder();
                for (Field field : fields)
                {
                    if (!ReflectUtils.isTransientOrStatic(field))
                    {
                        AbstractAttribute attrib = (AbstractAttribute) embeddable.getAttribute(field.getName());
                        Object obj = PropertyAccessorHelper.getObject(value, field);
                        compositeKey.append(
                                PropertyAccessorHelper.fromSourceToTargetClass(String.class,
                                        attrib.getBindableJavaType(), obj)).append("\001");
                    }
                }
                compositeKey.delete(compositeKey.lastIndexOf("\001"), compositeKey.length());
                value = compositeKey.toString();
            }
            else
            {
                fieldClazz = f.getType();
            }
        }
        else
        {
            StringTokenizer tokenizer = new StringTokenizer(jpaFieldName, ".");
            String embeddedFieldName = null;
            if (tokenizer.countTokens() > 1)
            {
                embeddedFieldName = tokenizer.nextToken();
                String fieldName = tokenizer.nextToken();
                Attribute embeddableAttribute = entity.getAttribute(embeddedFieldName);
                EmbeddableType embeddableType = metaModel.embeddable(embeddableAttribute.getJavaType());
                Attribute embeddedAttribute = embeddableType.getAttribute(fieldName);
                jpaFieldName = ((AbstractAttribute) embeddedAttribute).getJPAColumnName();
                fieldClazz = ((AbstractAttribute) embeddedAttribute).getBindableJavaType();
            }
            else
            {
                String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();

                if (!jpaFieldName.equals(discriminatorColumn))
                {
                    String fieldName = m.getFieldName(jpaFieldName);
                    Attribute col = entity.getAttribute(fieldName);
                    fieldClazz = ((AbstractAttribute) col).getBindableJavaType();
                }
            }
        }

        if (fieldClazz != null)
        {
            return HBaseUtils.getBytes(value, fieldClazz);
        }
        else
        {
            // Treat default as UTF8-Type. { in case of discriminator column}
            return HBaseUtils.getBytes(value, String.class);
        }
    }
382044
public String uploadFile(byte[] file, String ext, Map<String, String> metaInfo) {
        String path = "";
        TrackerServer trackerServer = null;
        StorageClient1 storageClient1 = null;
        try {
            trackerServer = fastDfsClientPool.borrowObject();
            storageClient1 = new StorageClient1(trackerServer, null);
            NameValuePair data[] = null;
            if (Lang.isNotEmpty(metaInfo)) {
                data = new NameValuePair[metaInfo.size()];
                int index = 0;
                for (Map.Entry<String, String> entry : metaInfo.entrySet()) {
                    data[index] = new NameValuePair(entry.getKey(), entry.getValue());
                    index++;
                }
            }
            path = storageClient1.uploadFile1(file, ext, data);
        } catch (Exception e) {
            throw Lang.makeThrow("[FastdfsService] upload file error : %s", e.getMessage());
        } finally {
            if (trackerServer != null)
                fastDfsClientPool.returnObject(trackerServer);
            storageClient1 = null;
        }
        return path;
    }
185217
public File getFile() throws IOException {
        URL url = getURL();
        return GrailsResourceUtils.getFile(url, getDescription());
    }
1210488
protected List<FileMeta> handleGetEntityMetaFiles(Class<? extends FileEntity> type, Integer entityId) {
        Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForGetEntityMetaFiles(
                BullhornEntityInfo.getTypesRestEntityName(type), entityId);
        String url = restUrlFactory.assembleGetEntityMetaFilesUrl();
        String jsonString = this.performGetRequest(url, String.class, uriVariables);
        EntityMetaFiles<? extends FileMeta> entityMetaFiles = restJsonConverter.jsonToEntityDoNotUnwrapRoot(jsonString,
                StandardEntityMetaFiles.class);
        if (entityMetaFiles == null || entityMetaFiles.getFileMetas() == null) {
            return Collections.emptyList();
        }
        return (List<FileMeta>) entityMetaFiles.getFileMetas();
    }
207377
protected File getMetadataBackupFile(final AbstractResource metadataResource,
                                         final SamlRegisteredService service) throws IOException {

        LOGGER.debug("Metadata backup directory is at [{}]", this.metadataBackupDirectory.getCanonicalPath());
        val metadataFileName = getBackupMetadataFilenamePrefix(metadataResource, service).concat(FILENAME_EXTENSION_XML);
        val backupFile = new File(this.metadataBackupDirectory, metadataFileName);
        if (backupFile.exists()) {
            LOGGER.info("Metadata file designated for service [{}] already exists at path [{}].", service.getName(), backupFile.getCanonicalPath());
        } else {
            LOGGER.debug("Metadata to fetch for service [{}] will be placed at [{}]", service.getName(), backupFile.getCanonicalPath());
        }
        return backupFile;
    }
574628
public static MetamodelImpl getMetamodel(final KunderaMetadata kunderaMetadata, String persistenceUnit)
    {
        MetamodelImpl metamodel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(persistenceUnit);

        return metamodel;
    }
1158103
public static ApkMeta getMetaInfo(File file) throws IOException {
        try (ApkFile apkFile = new ApkFile(file)) {
            return apkFile.getApkMeta();
        }
    }
1205773
public  InputStream getInputStream(File f)
	throws IOException
	{

		// use the magic numbers to determine the compression type,
		// use file extension only as 2nd choice

		int magic = 0;


		InputStream test = getInputStreamFromFile(f);
		magic = getMagicNumber(test);
		test.close();


		InputStream inputStream = null;

		String fileName = f.getName();

		if (magic == UncompressInputStream.LZW_MAGIC ) {
			// a Z compressed file
			return openCompressedFile(f);
		}

		else if (magic == GZIP_MAGIC ) {
			return openGZIPFile(f);
		}

		else if ( fileName.endsWith(".gz")) {
			return openGZIPFile(f);
		}

		else if ( fileName.endsWith(".zip")){

			ZipFile zipfile = new ZipFile(f);

			// stream to first entry is returned ...
			ZipEntry entry;
			Enumeration<? extends ZipEntry> e = zipfile.entries();
			if ( e.hasMoreElements()){
				entry = e.nextElement();
				inputStream = zipfile.getInputStream(entry);
			} else {
				throw new IOException ("Zip file has no entries");
			}

		}

		else if ( fileName.endsWith(".jar")) {

			JarFile jarFile = new JarFile(f);

			// stream to first entry is returned
			JarEntry entry;
			Enumeration<JarEntry> e = jarFile.entries();
			if ( e.hasMoreElements()){
				entry = e.nextElement();
				inputStream = jarFile.getInputStream(entry);
			} else {
				throw new IOException ("Jar file has no entries");
			}
		}

		else if ( fileName.endsWith(".Z")) {
			// unix compressed
			return openCompressedFile(f);

		}

		else {

			// no particular extension found, assume that it is an uncompressed file
			inputStream = getInputStreamFromFile(f);
		}

		return inputStream;
	}
1210401
@Override
    public File resolveArtifact(String coordinates) throws ArtifactException
    {
        ArtifactRequest request = new ArtifactRequest();
        Artifact artifact = new DefaultArtifact(coordinates);
        request.setArtifact(artifact);
        request.setRepositories(remoteRepositories);

        log.debug(String.format("Resolving artifact %s from %s", artifact, remoteRepositories));

        ArtifactResult result;
        try
        {
            result = repositorySystem.resolveArtifact(repositorySession, request);
        }
        catch (ArtifactResolutionException e)
        {
            throw new ArtifactException(e.getMessage(), e);
        }

        log.debug(String.format("Resolved artifact %s to %s from %s",
                artifact,
                result.getArtifact().getFile(),
                result.getRepository()));

        return result.getArtifact().getFile();
    }