You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/11/15 08:53:02 UTC

[GitHub] [james-project] quantranhong1999 opened a new pull request #747: JAMES-3534 Cassandra implementation for CustomIdentityDAO

quantranhong1999 opened a new pull request #747:
URL: https://github.com/apache/james-project/pull/747


   resolve https://github.com/linagora/james-project/issues/4424


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] Arsnael merged pull request #747: JAMES-3534 Cassandra implementation for CustomIdentityDAO

Posted by GitBox <gi...@apache.org>.
Arsnael merged pull request #747:
URL: https://github.com/apache/james-project/pull/747


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on a change in pull request #747: JAMES-3534 Cassandra implementation for CustomIdentityDAO

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #747:
URL: https://github.com/apache/james-project/pull/747#discussion_r749303784



##########
File path: server/data/data-jmap-cassandra/src/main/scala/org/apache/james/jmap/cassandra/identity/CassandraCustomIdentityDAO.scala
##########
@@ -0,0 +1,141 @@
+/** **************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                 *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ * ************************************************************** */
+
+package org.apache.james.jmap.cassandra.identity
+
+import com.datastax.driver.core.querybuilder.QueryBuilder
+import com.datastax.driver.core.querybuilder.QueryBuilder.{bindMarker, insertInto, select}
+import com.datastax.driver.core.{BoundStatement, PreparedStatement, Row, Session, UDTValue}
+import javax.inject.Inject
+import org.apache.james.backends.cassandra.init.CassandraTypesProvider
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor
+import org.apache.james.core.{MailAddress, Username}
+import org.apache.james.jmap.api.identity.{CustomIdentityDAO, IdentityCreationRequest, IdentityNotFoundException, IdentityUpdate}
+import org.apache.james.jmap.api.model.{EmailAddress, EmailerName, HtmlSignature, Identity, IdentityId, IdentityName, MayDeleteIdentity, TextSignature}
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable.{BCC, EMAIL, HTML_SIGNATURE, ID, MAY_DELETE, NAME, REPLY_TO, TABLE_NAME, TEXT_SIGNATURE, USER}
+import org.apache.james.jmap.cassandra.utils.EmailAddressTupleUtil
+import reactor.core.publisher.Mono
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+import scala.jdk.javaapi.CollectionConverters
+
+case class CassandraCustomIdentityDAO @Inject()(session: Session,
+                                                typesProvider: CassandraTypesProvider) extends CustomIdentityDAO {
+  val executor: CassandraAsyncExecutor = new CassandraAsyncExecutor(session)
+  val emailAddressTupleUtil: EmailAddressTupleUtil = EmailAddressTupleUtil(typesProvider)
+
+  val insertStatement: PreparedStatement = session.prepare(insertInto(TABLE_NAME)
+    .value(USER, bindMarker(USER))
+    .value(ID, bindMarker(ID))
+    .value(NAME, bindMarker(NAME))
+    .value(EMAIL, bindMarker(EMAIL))
+    .value(REPLY_TO, bindMarker(REPLY_TO))
+    .value(BCC, bindMarker(BCC))
+    .value(TEXT_SIGNATURE, bindMarker(TEXT_SIGNATURE))
+    .value(HTML_SIGNATURE, bindMarker(HTML_SIGNATURE))
+    .value(MAY_DELETE, bindMarker(MAY_DELETE)))
+
+  val selectAllStatement: PreparedStatement = session.prepare(select()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER))))
+
+  val selectOneStatement: PreparedStatement = session.prepare(select()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER)))
+    .and(QueryBuilder.eq(ID, bindMarker(ID))))
+
+  val deleteOneStatement: PreparedStatement = session.prepare(QueryBuilder.delete()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER)))
+    .and(QueryBuilder.eq(ID, bindMarker(ID))))
+
+  override def save(user: Username, creationRequest: IdentityCreationRequest): SMono[Identity] =
+    SMono.fromCallable(() => IdentityId.generate)

Review comment:
       Generating the id should likely be done out of the mono. That way retrying would insert the very same value (idempotance)

##########
File path: server/data/data-jmap-cassandra/src/main/scala/org/apache/james/jmap/cassandra/identity/CassandraCustomIdentityModule.scala
##########
@@ -0,0 +1,48 @@
+/** **************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                 *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ * ************************************************************** */
+
+package org.apache.james.jmap.cassandra.identity
+
+import com.datastax.driver.core.DataType.{cboolean, text, uuid}
+import com.datastax.driver.core.schemabuilder.SchemaBuilder
+import org.apache.james.backends.cassandra.components.CassandraModule
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable.{BCC, EMAIL, EMAIL_ADDRESS, EmailAddress, HTML_SIGNATURE, ID, MAY_DELETE, NAME, REPLY_TO, TEXT_SIGNATURE, USER}
+
+object CassandraCustomIdentityModule {
+  val MODULE: CassandraModule = CassandraModule.builder()
+    .`type`(EMAIL_ADDRESS)
+    .statement(statement => statement
+      .addColumn(EmailAddress.NAME, text())
+      .addColumn(EmailAddress.EMAIL, text()))
+
+    .table(CassandraCustomIdentityTable.TABLE_NAME)
+    .comment("Hold user custom identities data")

Review comment:
       Mention Jmap rfc-8621 in this comment imo...

##########
File path: server/data/data-jmap-cassandra/src/main/scala/org/apache/james/jmap/cassandra/identity/CassandraCustomIdentityDAO.scala
##########
@@ -0,0 +1,141 @@
+/** **************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                 *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ * ************************************************************** */
+
+package org.apache.james.jmap.cassandra.identity
+
+import com.datastax.driver.core.querybuilder.QueryBuilder
+import com.datastax.driver.core.querybuilder.QueryBuilder.{bindMarker, insertInto, select}
+import com.datastax.driver.core.{BoundStatement, PreparedStatement, Row, Session, UDTValue}
+import javax.inject.Inject
+import org.apache.james.backends.cassandra.init.CassandraTypesProvider
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor
+import org.apache.james.core.{MailAddress, Username}
+import org.apache.james.jmap.api.identity.{CustomIdentityDAO, IdentityCreationRequest, IdentityNotFoundException, IdentityUpdate}
+import org.apache.james.jmap.api.model.{EmailAddress, EmailerName, HtmlSignature, Identity, IdentityId, IdentityName, MayDeleteIdentity, TextSignature}
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable
+import org.apache.james.jmap.cassandra.identity.tables.CassandraCustomIdentityTable.{BCC, EMAIL, HTML_SIGNATURE, ID, MAY_DELETE, NAME, REPLY_TO, TABLE_NAME, TEXT_SIGNATURE, USER}
+import org.apache.james.jmap.cassandra.utils.EmailAddressTupleUtil
+import reactor.core.publisher.Mono
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+import scala.jdk.javaapi.CollectionConverters
+
+case class CassandraCustomIdentityDAO @Inject()(session: Session,
+                                                typesProvider: CassandraTypesProvider) extends CustomIdentityDAO {
+  val executor: CassandraAsyncExecutor = new CassandraAsyncExecutor(session)
+  val emailAddressTupleUtil: EmailAddressTupleUtil = EmailAddressTupleUtil(typesProvider)
+
+  val insertStatement: PreparedStatement = session.prepare(insertInto(TABLE_NAME)
+    .value(USER, bindMarker(USER))
+    .value(ID, bindMarker(ID))
+    .value(NAME, bindMarker(NAME))
+    .value(EMAIL, bindMarker(EMAIL))
+    .value(REPLY_TO, bindMarker(REPLY_TO))
+    .value(BCC, bindMarker(BCC))
+    .value(TEXT_SIGNATURE, bindMarker(TEXT_SIGNATURE))
+    .value(HTML_SIGNATURE, bindMarker(HTML_SIGNATURE))
+    .value(MAY_DELETE, bindMarker(MAY_DELETE)))
+
+  val selectAllStatement: PreparedStatement = session.prepare(select()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER))))
+
+  val selectOneStatement: PreparedStatement = session.prepare(select()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER)))
+    .and(QueryBuilder.eq(ID, bindMarker(ID))))
+
+  val deleteOneStatement: PreparedStatement = session.prepare(QueryBuilder.delete()
+    .from(TABLE_NAME)
+    .where(QueryBuilder.eq(USER, bindMarker(USER)))
+    .and(QueryBuilder.eq(ID, bindMarker(ID))))
+
+  override def save(user: Username, creationRequest: IdentityCreationRequest): SMono[Identity] =
+    SMono.fromCallable(() => IdentityId.generate)
+      .map(creationRequest.asIdentity)
+      .flatMap(identity => insert(user, identity))
+
+  override def list(user: Username): SFlux[Identity] =
+    SFlux.fromPublisher(executor.executeRows(selectAllStatement.bind().setString(USER, user.asString()))
+      .map(toIdentity(_)))
+
+  override def update(user: Username, identityId: IdentityId, identityUpdate: IdentityUpdate): SMono[Unit] = {

Review comment:
       Please remove useless {} everywhere




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org