小编Bha*_*a S的帖子

Java 8使用2个字段排序

根据一些条件,我从MongoDB读取数据并创建一个List<Document>带结果集.

List<Document> documentList = new ArrayList<Document>();
Run Code Online (Sandbox Code Playgroud)

样本记录看起来像:

documentList: [
    Document{
        { _id=5975ff00a213745b5e1a8ed9,
            u_id=,
            visblty = 1,
            c_id=5975ff00a213745b5e1a8ed8,                
            batchid=null,
            pdate=Tue Jul 11 17:52:25 IST 2017, 
            locale=en_US,
            subject = "Document2"
        }     },
    Document{
        { _id=597608aba213742554f537a6,
            u_id=,
            visblty = 1,
            c_id=597608aba213742554f537a3, 
            batchid=null,
            pdate=Fri Jul 28 01:26:22 IST 2017,
            locale=en_US,
            subject = "Document2"
        }    } 
]
Run Code Online (Sandbox Code Playgroud)

使用此documentList,我再次使用某些条件进行过滤,然后我需要根据某些条件(我将在请求中获取)对过滤器记录进行排序.

List<Document> outList = documentList.stream()
                .filter(d -> d.getInteger("visblty") == 1
                && (!StringUtils.isEmpty(req.pdate())? (d.getDate(CommonConstants.PDATE).after(afterDate)): true) 
                && (!StringUtils.isEmpty(req.pdate())? (d.getDate(CommonConstants.PDATE).before(beforeDate)): true)
                .sorted().skip(4).limit()
                .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

不确定如何排序(动态需要根据输入更改排序顺序,它看起来像" pdate by DESC"或" subject …

java sorting java-8 java-stream

10
推荐指数
3
解决办法
1万
查看次数

Mockito FindIterable&lt;Document&gt;

我正在尝试为以下方法编写 JUnit 测试用例,我正在使用 Mockito 框架。

方法:

public EmplInfo getMetaData(String objectId) {

        objectId = new StringBuffer(objectId).reverse().toString();
        try{
            BasicDBObject whereClauseCondition = getMetaDataWhereClause(objectId);
            EmplInfo emplinfo= new EmplInfo ();
            emplinfo.set_id(objectId);
            FindIterable<Document> cursorPersonDoc = personDocCollection.find(whereClauseCondition);
            for (Document doc : cursorPersonDoc) {
                emplinfo.setEmplFirstName(doc.getString("firstname"));
                emplinfo.setEmplLastName(doc.getString("lastname"));
                break;
            }
            return emplinfo;
        }catch(Exception e){
         e.printstacktrace();
        }
Run Code Online (Sandbox Code Playgroud)

朱尼特:

@Test
public void testGetMetaData() throws Exception {
    String docObjectId = "f2da8044b29f2e0a35c0a2b5";
    BasicDBObject dbObj = personDocumentRepo.getMetaDataWhereClause(docObjectId);
    FindIterable<Document> findIterable = null;
    Mockito.when(collection.find(dbObj)).thenReturn(findIterable);
    personDocumentRepo.getMetaData(docObjectId);
}
Run Code Online (Sandbox Code Playgroud)

在“personDocumentRepo.getMetaData(docObjectId)”中得到空点期望,因为我“返回”了空的findIterable。不确定如何将虚拟/测试值分配给 findIterable。

请指教。

谢谢!婆罗提

java junit4 mockito mongodb-java

7
推荐指数
2
解决办法
5387
查看次数

Kafka 流异常:GroupAuthorizationException

我正在开发一个 Kafka-Stream 应用程序,它将从输入 Kafka 主题中读取消息并过滤不需要的数据并推送到输出 Kafka 主题。

卡夫卡流配置:

@Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
public KafkaStreamsConfiguration kStreamsConfigs() {

    Map<String, Object> streamsConfiguration = new HashMap<>();
    streamsConfiguration.put(ConsumerConfig.GROUP_ID_CONFIG, "abcd");
    streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "QC-NormalizedEventProcessor-v1.0.0");
    streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "test:9072");
    streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    streamsConfiguration.put(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE);
    streamsConfiguration.put(StreamsConfig.producerPrefix(ProducerConfig.ACKS_CONFIG), -1);
    streamsConfiguration.put(StreamsConfig.REPLICATION_FACTOR_CONFIG, 3);
    streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
    streamsConfiguration.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, kafkaConsumerProperties.getConsumerJKSFileLocation());
    streamsConfiguration.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, kafkaConsumerProperties.getConsumerJKSPwd());
    streamsConfiguration.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL");
    streamsConfiguration.put(SASL_MECHANISM, "PLAIN");

    return new KafkaStreamsConfiguration(streamsConfiguration);
}
Run Code Online (Sandbox Code Playgroud)

KStream过滤逻辑:

@Bean
public KStream<String, String> kStreamJson(StreamsBuilder builder) {

    KStream<String, String> stream = builder.stream(kafkaConsumerProperties.getConsumerTopic(), Consumed.with(Serdes.String(), Serdes.String()));
    /** Printing the source message */
    stream.foreach((key, value) -> LOGGER.info(THREAD_NO + Thread.currentThread().getId() + " …
Run Code Online (Sandbox Code Playgroud)

apache-kafka apache-kafka-streams spring-kafka

7
推荐指数
1
解决办法
1万
查看次数

使用Axis2的Spring Boot应用程序 - /BOOT-INF/lib/addressing-1.6.2.mar文件无法找到

在SOAP调用期间我得到一个以下异常,但在本地我没有得到任何异常.

我真的不确定为什么寻址-1.6.2.mar引用应用程序jar路径.

Axis2结构:

在此输入图像描述

VM参数:

JAVA_HOME=/apps/jdk/jdk1.8.0_111

ANTIFRAUD_HOME=/apps/Benefits/AntiFraud/r20/dev

nohup $JAVA_HOME/bin/java-Dspring.profiles.active=dev -Dspring.config.location=file:$ANTIFRAUD_HOME/properties/application.properties -Dlogging.config=file:$ANTIFRAUD_HOME/properties/log4j2.xml -Djava.security.auth.login.config=file:$ANTIFRAUD_HOME/properties/kafka-client-jaas.conf -DConfigPath=$ANTIFRAUD_HOME/hasbroResources -Daxis2.repo=$ANTIFRAUD_HOME/hasbroResources/resources/axis2/repository -Daxis2.xml=$ANTIFRAUD_HOME/hasbroResources/resources/axis2/conf/axis2.xml  -jar $ANTIFRAUD_HOME/lib/a-notification-0.0.1.jar &
Run Code Online (Sandbox Code Playgroud)

例外:

2019-01-31T08:09:04.603-0600 INFO Deploying module: metadataExchange-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/mex-1.6.2.mar
2019-01-31T08:09:04.603-0600 INFO Deploying module: metadataExchange-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/mex-1.6.2.mar
2019-01-31T08:09:04.610-0600 INFO Deploying module: mtompolicy-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/mtompolicy-1.6.2.mar
2019-01-31T08:09:04.611-0600 INFO Deploying module: mtompolicy-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/mtompolicy-1.6.2.mar
2019-01-31T08:09:04.642-0600 INFO Deploying module: ping-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/ping-1.6.2.mar
2019-01-31T08:09:04.645-0600 INFO Deploying module: ping-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/ping-1.6.2.mar
2019-01-31T08:09:04.663-0600 INFO Deploying module: script-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/scripting-1.6.2.mar
2019-01-31T08:09:04.663-0600 INFO Deploying module: script-1.6.2 - file:/apps/Benefits/AntiFraud/r20/dev/hasbroResources/resources/axis2/repository/modules/scripting-1.6.2.mar
2019-01-31T08:09:04.674-0600 INFO Deploying module: soapmonitor-1.6.2 - …
Run Code Online (Sandbox Code Playgroud)

java spring axis axis2 spring-boot

5
推荐指数
0
解决办法
293
查看次数

使用Java从mongodb读取blob(二进制)数据时出错

我无法使用Java 3.4.2驱动程序从MongoDB中读取blob(二进制)记录。

    BasicDBObject whereClause = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(new BasicDBObject("blobcontentid", "20160601201035069394000000"));
    whereClause.put("$and", obj);

    MongoCursor<Document> cursor = contentcollection.find(whereClause).iterator();

    while (cursor.hasNext()) {
        Document object = cursor.next();
        System.out.println(object.getString("blobcontentid"));
        if (object.get("content") != null){
            byte[] content = (byte []) object.get("content");   
        } else {
            System.out.println("Content is empty");
        }           
    }
Run Code Online (Sandbox Code Playgroud)

错误:java.lang.ClassCastException:org.bson.types.Binary无法转换为[B

在DB2中,相同的记录正在读取。byte [] content = aResult.getBytes(“ CONTENT”);

先感谢您!巴拉提

java mongodb mongodb-java

2
推荐指数
1
解决办法
2643
查看次数

如何使用 Java 从 MongoDB 读取日期(时间戳)

我正在尝试以以下格式从 MongoDB 读取日期字段

Formate: YYYY-MM-dd HH:mm:ss.SSSSSS

2017-01-23-10.46.07.812000 - DB2
2017-01-23T16:46:07.812Z   - Stored in MongoDB (While viewing from GUI tool)
Mon Jan 23 22:16:07 IST 2017 - Result/Reading from MongoDB

// Formatter for the input date
final DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy");
final ZonedDateTime dateFiledParsed = ZonedDateTime.parse(dateFiled.toString(), inputFormat);
final DateTimeFormatter outputFormat3 = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSSSSS");
System.out.println(outputFormat3.format(publicationDateParsed));

Result: 2017-01-23 22:16:07.000000
Run Code Online (Sandbox Code Playgroud)

结果是 2017-01-23 22:16:07。000 000,而不是000它应该是812(原始值:2017-01-23-10.46.07.812000)

注意:使用 MongoDB Java 驱动程序 3.4。

先感谢您!

婆罗提

java mongodb mongodb-java mongodb-java-3.3.0

2
推荐指数
1
解决办法
7818
查看次数

Java 8流过滤器 - 基于排序的pdate

我试图在过滤器中对字段进行排序.

输入文件/样本记录:

DocumentList: [
    Document{
        {
            _id=5975ff00a213745b5e1a8ed9,
            u_id=,
            mailboxcontent_id=5975ff00a213745b5e1a8ed8,                
            idmapping=Document{
                {ptype=PDF, cid=00988, normalizedcid=00988, systeminstanceid=, sourceschemaname=, pid=0244810006}
            },
            batchid=null,
            pdate=Tue Jul 11 17:52:25 IST 2017, locale=en_US
        }
    },
    Document{
        {
            _id=597608aba213742554f537a6,
            u_id=,
            mailboxcontent_id=597608aba213742554f537a3, 
            idmapping=Document{
                {platformtype=PDF, cid=00999, normalizedcid=00999, systeminstanceid=, sourceschemaname=, pid=0244810006}
            },
            batchid=null,
            pdate=Fri Jul 28 01:26:22 IST 2017,
            locale=en_US
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

在这里,我需要根据pdate进行排序.

List<Document> outList = documentList.stream()
    .filter(p -> p.getInteger(CommonConstants.VISIBILITY) == 1)
    .parallel()
    .sequential()
    .collect(Collectors.toCollection(ArrayList::new))
    .sort()
    .skip(skipValue)
    .limit(limtValue);
Run Code Online (Sandbox Code Playgroud)

不知道如何排序

"order by pdate DESC"
Run Code Online (Sandbox Code Playgroud)

先感谢您!

java sorting java-8 java-stream

2
推荐指数
1
解决办法
3839
查看次数

如何在Java 8流过滤器中基于子文档过滤Mongo文档

我试图过滤子文档.

样本记录:

[Document{{_id=597608aba213742554f537a6, upp_id=, content_id=597608aba213742554f537a3, idmapping=Document{{ptype=PDF, clientid=12345, normalizedclientid=12345, systeminstanceid=, sourceschemaname=, platforminternalid=0987654321}}, batchid=null, locale=en_US}}]
Run Code Online (Sandbox Code Playgroud)

我需要使用idmapping.ptype = PDF进行过滤

MongoCursor<Document> cursor = mailboxitemCollection.find(whereClause).iterator();
List<Document> documentList = new ArrayList<Document>();

while (cursor.hasNext()) {
  Document object = cursor.next();
  documentList.add(object);
}

 List<Document> outList = documentList.stream()
        .filter(p -> p.getInteger(CommonConstants.VISIBILITY) == 1
            && (!StringUtils.isEmpty(req.ptype())? (p.getString("idmapping.ptype").equalsIgnoreCase(req.ptype())) : true)
            ).parallel().sequential().collect(Collectors.toCollection(ArrayList::new));

System.out.println(outList);
System.out.println(outList.size());
Run Code Online (Sandbox Code Playgroud)

我得到Null Point异常,无法从List documentList中读取sub/embed文档.

先感谢您!Bharathi

java stream mongodb java-8 java-stream

1
推荐指数
1
解决办法
377
查看次数