diff --git a/.gitignore b/.gitignore
index 5e5e536..357d5fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,3 +52,4 @@ resources/templates/css/**
resources/templates/js/**
resources/templates/fonts/**
dist
+.classpath
\ No newline at end of file
diff --git a/dialogflow-fun-java/.classpath b/dialogflow-fun-java/.classpath
deleted file mode 100644
index 92b9cb8..0000000
--- a/dialogflow-fun-java/.classpath
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dialogflow-fun-java/.gitignore b/dialogflow-fun-java/.gitignore
index b73fbb0..96b48fb 100644
--- a/dialogflow-fun-java/.gitignore
+++ b/dialogflow-fun-java/.gitignore
@@ -51,3 +51,4 @@ resources/templates/css/**
resources/templates/js/**
resources/templates/fonts/**
dist
+.classpath
\ No newline at end of file
diff --git a/dialogflow-fun-java/src/main/java/CreateAgent.java b/dialogflow-fun-java/src/main/java/CreateAgent.java
index 1de41eb..fa91057 100644
--- a/dialogflow-fun-java/src/main/java/CreateAgent.java
+++ b/dialogflow-fun-java/src/main/java/CreateAgent.java
@@ -1,77 +1,31 @@
import java.io.IOException;
-import java.util.List;
-import com.google.cloud.dialogflow.v2beta1.EntityType;
-import com.google.cloud.dialogflow.v2beta1.EntityTypeName;
-import com.google.cloud.dialogflow.v2beta1.EntityTypesClient;
-import com.google.cloud.dialogflow.v2beta1.ProjectAgentName;
import com.google.cloud.dialogflow.v2beta1.Agent;
import com.google.cloud.dialogflow.v2beta1.AgentsClient;
import com.google.cloud.dialogflow.v2beta1.ProjectName;
-import com.google.cloud.dialogflow.v2beta1.EntityType.Entity;
public class CreateAgent {
private static final String GOOGLE_AUTH_ENV_NAME = "GOOGLE_APPLICATION_CREDENTIALS";
- private static final String PROJECT_NAME = "dialogflow-fun";
private static final String AGENT_NAME = "dialogflow-fun-agent";
private static final String AGENT_ID = "ac522b80-e75b-40cd-9493-269fbb4ef634";
private static final String ENTITY_TYPE_ID = "Developer";
- public static void main(String[] args) {
+ private static EntityCreator entityCreator = new EntityCreator();
+
+ public static void main(String[] args) throws IOException {
if (!googleAuthOk()) {
System.out.println("Error with Google Authentication. Exiting...");
System.exit(0);
}
- getAgentInfo();
- getEntitiesInfo();
+ entityCreator.deleteAllEntityTypes();
+ entityCreator.createContactEntityType();
System.out.println("Done");
}
- public static void getEntitiesInfo() {
-
- // ENTITY TYPES
- // https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/dialogflow/v2/package-summary.html
- // * **System** - entities that are defined by the Dialogflow API for common
- // data types such as date, time, currency, and so on. A system entity is
- // represented by the `EntityType` type.
- // * **Developer** - entities that are defined by you that represent actionable
- // data that is meaningful to your application. For example, you could define a
- // `pizza.sauce` entity for red or white pizza sauce, a `pizza.cheese` entity
- // for the different types of cheese on a pizza, a `pizza.topping` entity for
- // different toppings, and so on. A developer entity is represented by the
- // `EntityType` type.
- // * **User** - entities that are built for an individual user such as
- // favorites, preferences, playlists, and so on. A user entity is represented by
- // the [SessionEntityType][google.cloud.dialogflow.v2.SessionEntityType] type.
-
- System.out.println("==========");
- System.out.println("Getting Entities info");
-
- try {
- EntityTypesClient entityTypesClient = EntityTypesClient.create();
- ProjectAgentName parent = ProjectAgentName.of(PROJECT_NAME);
- for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) {
- System.out.println(entityType.getDisplayName());
- List entities = entityType.getEntitiesList();
- entities.forEach(CreateAgent::printEntity);
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- System.out.println("==========");
-
- }
-
- public static void printEntity(Entity entity) {
- System.out.println(entity.getValue());
- }
-
public static void getAgentInfo() {
System.out.println("==========");
System.out.println("Getting Agent info");
diff --git a/dialogflow-fun-java/src/main/java/EntityCreator.java b/dialogflow-fun-java/src/main/java/EntityCreator.java
new file mode 100644
index 0000000..40461fd
--- /dev/null
+++ b/dialogflow-fun-java/src/main/java/EntityCreator.java
@@ -0,0 +1,76 @@
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.google.cloud.dialogflow.v2beta1.EntityType;
+import com.google.cloud.dialogflow.v2beta1.EntityTypesClient;
+import com.google.cloud.dialogflow.v2beta1.ProjectAgentName;
+import com.google.cloud.dialogflow.v2beta1.EntityType.Entity;
+import com.google.cloud.dialogflow.v2beta1.EntityType.Kind;
+
+import data.ReadNames;
+
+public class EntityCreator {
+
+ private static final String CONTACT_ENTITY_NAME = "names_composite";
+ private static final String PROJECT_NAME = "dialogflow-fun";
+
+ private ReadNames namesReader = new ReadNames();
+
+ public void createContactEntityType() {
+ try {
+ EntityTypesClient entityTypesClient = EntityTypesClient.create();
+ ProjectAgentName parent = ProjectAgentName.of(PROJECT_NAME);
+
+ List names = namesReader.getListOfNames();
+ List contactEntities = names.stream().map(n -> Entity.newBuilder().setValue(n).build())
+ .collect(Collectors.toList());
+
+ EntityType contactEntityType = EntityType.newBuilder().setDisplayName(CONTACT_ENTITY_NAME)
+ .setKind(Kind.KIND_MAP).addAllEntities(contactEntities).build();
+
+ entityTypesClient.createEntityType(parent, contactEntityType);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void deleteAllEntityTypes() throws IOException {
+ EntityTypesClient entityTypesClient = EntityTypesClient.create();
+ ProjectAgentName parent = ProjectAgentName.of(PROJECT_NAME);
+
+ for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) {
+ System.out.println("Deleting " + entityType.getDisplayName() + " with name " + entityType.getName());
+ entityTypesClient.deleteEntityType(entityType.getName());
+ }
+
+ }
+
+ public void getEntitiesInfo() {
+
+ System.out.println("==========");
+ System.out.println("Getting Entities info");
+
+ try {
+ EntityTypesClient entityTypesClient = EntityTypesClient.create();
+ ProjectAgentName parent = ProjectAgentName.of(PROJECT_NAME);
+ for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) {
+ System.out.println(entityType.getDisplayName());
+ List entities = entityType.getEntitiesList();
+ entities.forEach(EntityCreator::printEntity);
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("==========");
+
+ }
+
+ public static void printEntity(Entity entity) {
+ System.out.println(entity.getValue());
+ }
+
+}
\ No newline at end of file
diff --git a/dialogflow-fun-java/src/main/java/data/ReadNames.java b/dialogflow-fun-java/src/main/java/data/ReadNames.java
new file mode 100644
index 0000000..8933fc4
--- /dev/null
+++ b/dialogflow-fun-java/src/main/java/data/ReadNames.java
@@ -0,0 +1,27 @@
+package data;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+public class ReadNames {
+
+ private static final String NAMES_FILE_LOCATION = "names2";
+
+ public List getListOfNames() throws FileNotFoundException {
+
+ List names = new ArrayList<>();
+ File namesFile = new File(getClass().getClassLoader().getResource(NAMES_FILE_LOCATION).getFile());
+ Scanner scanner = new Scanner(namesFile);
+
+ while (scanner.hasNextLine()) {
+ names.add(scanner.nextLine().trim());
+ }
+
+ scanner.close();
+ return names;
+ }
+
+}
\ No newline at end of file
diff --git a/names b/dialogflow-fun-java/src/main/resources/names
similarity index 99%
rename from names
rename to dialogflow-fun-java/src/main/resources/names
index afffa01..5f1fc6b 100644
--- a/names
+++ b/dialogflow-fun-java/src/main/resources/names
@@ -247,4 +247,4 @@ Allyn Claire
Magdalene Michna
Leticia Jorgenson
Jaleesa Dally
-Candace Tootle
+Candace Tootle
\ No newline at end of file
diff --git a/dialogflow-fun-java/src/main/resources/names_composite b/dialogflow-fun-java/src/main/resources/names_composite
new file mode 100644
index 0000000..31c4347
--- /dev/null
+++ b/dialogflow-fun-java/src/main/resources/names_composite
@@ -0,0 +1,10 @@
+mum
+dad
+my mum
+my dad
+my @sys.person:person
+uncle @sys.person:person
+aunt @sys.person:person
+grandma @sys.person:person
+grandpa @sys.person:person
+@sys.person:person
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..93c7a47
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,19 @@
+
+
+ 4.0.0
+
+ pom
+ fr.lengrand
+ dialogflow-fun-complete
+ 1.0-SNAPSHOT
+
+
+ 11
+ 11
+ 11
+
+
+
+ dialogflow-fun-java
+
+
\ No newline at end of file