How can i set GCP Application name?
2018-Nov-22 11:18:18.283 WARN [http-nio-8080-exec-9]
c.g.a.c.g.s.AbstractGoogleClient - Application name is not set.
Call
Builder#setApplicationName.
I have following constructor in my class.
private final GoogleCredential googleCredential;
private final String projectId;
private final String zone;
private final String region;
private GcpClient(GcpAccountSettings settings) throws
GcpClientException {
try {
this.googleCredential =
getCredential(settings.getClientEmail(),
settings.getPrivateKey());
} catch (GeneralSecurityException | IOException e) {
throw new GcpClientException(e);
}
this.projectId = settings.getProjectId();
this.zone = settings.getZone();
this.region = settings.getRegions();
}
Im really hoping your help.
We can set application name like following.
Compute compute =
new Compute.Builder(googleCredential.getTransport(),
googleCredential.getJsonFactory(), googleCredential)
.setApplicationName(projectId).build();
if you need more details please follow below link
how to set application name
Related
I tried to rebuild the sample from the XDocReport documentation, but when i try to create tables or fill them. It always fails due to the follwing error. I cannot figure out what the issue is...
I have updated all the dependencies and tried different syntax in the .odt file.
ERROR:
Apr. 12, 2022 10:21:05 VORM. freemarker.log._JULLoggerFactory$JULLogger error
SEVERE: Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> devs.name [in template "fr.opensagres.xdocreport.document.odt.ODTReport#57855c9a!content.xml" at line 5, column 11]
----
Tip: It's the step after the last dot that caused this error, not those before it.
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use [#if myOptionalVar??]when-present[#else]when-missing[/#if]. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${devs.name} auto-escaped [in template "fr.opensagres.xdocreport.document.odt.ODTReport#57855c9a!content.xml" at line 5, column 9]
----
Java stack trace (for programmers):
----
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481)
at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401)
at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370)
at freemarker.core.BuiltInForLegacyEscaping._eval(BuiltInForLegacyEscaping.java:34)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.Expression.evalAndCoerceToStringOrUnsupportedMarkup(Expression.java:139)
at freemarker.core.BuiltInForString.getTargetString(BuiltInForString.java:34)
at freemarker.core.BuiltInForString._eval(BuiltInForString.java:29)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.MethodCall._eval(MethodCall.java:55)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
at freemarker.core.Environment.visit(Environment.java:383)
at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321)
at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:657)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:347)
at freemarker.core.Environment.visit(Environment.java:353)
at freemarker.core.Environment.visit(Environment.java:353)
at freemarker.core.Environment.process(Environment.java:326)
at fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.process(FreemarkerTemplateEngine.java:163)
at fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.processNoCache(FreemarkerTemplateEngine.java:122)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:118)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:83)
at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:772)
at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:518)
at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:484)
at report_creation.fillList.main(fillList.java:51)
I am currently using this code:
fillList.java
public class fillList {
public static void main(String[] args) {
try {
// 1) Load ODT file by filling Velocity template engine and cache
// it to the registry
InputStream in = fillList.class.getResourceAsStream("Test.odt");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Freemarker);
// 2) Create fields metadata to manage lazy loop (#foreach velocity)
// for table row.
FieldsMetadata metadata = new FieldsMetadata();
metadata.addFieldAsList("developers.name");
metadata.addFieldAsList("developers.lastName");
metadata.addFieldAsList("developers.mail");
report.setFieldsMetadata(metadata);
// 3) Create context Java model
IContext context = report.createContext();
Project project = new Project("Create Dynamic Reports", 101);
context.put("project", project);
// Register developers list
List<Developer> developers = new ArrayList<>();
developers.add(new Developer("ZERR", "Angelo", "angelo.zerr#gmail.com"));
developers.add(new Developer("Leclercq", "Pascal", "pascal.leclercq#gmail.com"));
context.put("developers", developers);
// 4) Generate report by merging Java model with the ODT
OutputStream out = new FileOutputStream(new File("Test2_out.odt"));
report.process(context, out);
System.out.println("Report creation successfully completed!");
} catch (IOException e) {
System.err.println("[Debug Assistent]: No report created! >> IOException");
e.printStackTrace();
} catch (XDocReportException e) {
System.err.println("[Debug Assistent]: No report created! >> XDocReportException");
e.printStackTrace();
}
}
}
Project.java
public class Project {
private final String name;
private final Integer ID;
public Project(String name, Integer id) {
this.name = name;
this.ID = id;
}
public String getName() {
return name;
}
public Integer getID() {
return ID;
}
}
Developer.java
public class Developer {
private final String name;
private final String lastName;
private final String mail;
public Developer(String name, String lastName, String mail) {
this.name = name;
this.lastName = lastName;
this.mail = mail;
}
public String getFirstName() {
return name;
}
public String getLastName() {
return lastName;
}
public String getMail() {
return mail;
}
}
This is the .odt file i am using.
In the Developer class you have getFirstName instead of getName. Hence dev.name won't work.
Cut to the chase:
I've got a class User, which holds an instance of Security:
public class User {
private long id;
private String name;
Security security;
public User(String nname, String password, String userName, String email) {
this.id = 0;
this.name = nname;
this.security = new Security(password, userName, email);
}
/**
* getters and setters
*/
}
Yes, the id is currently temporary for testing, and Security has a very similar format.
Next I run this code for setting up my firebase entry:
FirebaseApp app = FirebaseApp.initializeApp(options);
this.db = com.google.firebase.cloud.FirestoreClient.getFirestore(app);
ApiFuture<WriteResult> collectionsApiFuture =
db.collection("users").document(user.getName()).set(user);
System.out.println(collectionsApiFuture.get().getUpdateTime().toString());
And I use this as my test data:
FirebaseInitialise testFirebase = new FirebaseInitialise();
User tempUser = new User("Ollie", "123", "OlliesRealm", "email#mail.com");
testFirebase.initialize(tempUser);
However, when I run the code, the relation appears in the firestore application as:
id: 0
name: "Ollie"
security:
unlocked: true
userName: "OlliesRealm"
I would like it to either properly hold the full information for security, which it seems to be unable to do, or to just hold an ID of it without actually having the security info stored in user.
If anyone could suggest anything or help me out that would be greatly appreciated!!
To be able to get Security as a full object you just need to save it specifically when uploading on the Firestore database.
#Override
public String createUser(user user) {
String id = UUID.randomUUID().toString();
DocumentReference document = userCollection.document(id);
Map<String, Object> data = Maps.newHashMap();
data.put("name", user.getName());
data.put("security", user.getSecurity());
try {
document.set(data).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
If you want to have them separately you just need to create a different collection for the Security and save it there with something like that:
#Override
public String createUser(user user) {
String id = UUID.randomUUID().toString();
DocumentReference userDocument = userCollection.document(id);
DocumentReference securityDocument = SecurityCollection.document(id);
Security temp = user.getSecurity();
Map<String, Object> userData = Maps.newHashMap();
Map<String, Object> securityData = Maps.newHashMap();
userData.put("name", user.getName());
userData.put("security", user.getSecurity());
securityData.put("username", security.getUserName());
securityData.put("password", security.getPassword());
securityData.put("email", security.getEmail());
try {
userDocument.set(userData).get();
securityDocument.set(securityData).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
I'm trying to read .drl drools rules in my REST with Java (JAX-RS) using Jersey.
I put my .drl files in WEB-INF/rules folder, and tried to read them with this lines of code
private RuleBase trainingRules;
private RuleBase kuperMaleTrainingResultsRules;
private RuleBase kuperFemaleTrainingResultsRules;
private RuleBase basicTrainingResultsRules;
private final String trainingRulesPath = "/WEB-INF/rules/ZatraziTrening.drl";
private final String kuperMaleTrainingResultsPath = "/WEB-INF/rules/KuperMuski.drl";
private final String kuperFemaleTrainingResultsPath = "/WEB-INF/rules/KuperZenski.drl";
private final String trainingResultsRulesPath = "/WEB-INF/rules/RezultatiTreninga.drl";
private static ControllerDrools INSTANCE;
private ControllerDrools() {
try {
this.trainingRules = loadRules(trainingRulesPath);
this.kuperMaleTrainingResultsRules = loadRules(kuperMaleTrainingResultsPath);
this.kuperFemaleTrainingResultsRules = loadRules(kuperFemaleTrainingResultsPath);
this.basicTrainingResultsRules = loadRules(trainingResultsRulesPath);
} catch (DroolsParserException | IOException e) {
// TODO: dodati ispis poruke u logger
e.printStackTrace();
}
}
private RuleBase loadRules(String rulesPath) throws DroolsParserException, IOException {
Reader source = new InputStreamReader(ControllerDrools.class.getResourceAsStream(rulesPath));
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(source);
Package pkg = builder.getPackage();
// Kreiranje baze znanja i dodavanje paketa u nju
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
return ruleBase;
}
public static ControllerDrools getInstance() {
if (INSTANCE == null) {
INSTANCE = new ControllerDrools();
}
return INSTANCE;
}
/**
* Get's the training from drools
* #param user
* #return training to do
*/
public Training getTrening(User user) {
user.setNumberOfTrainingInCategory(user.getNumberOfTrainingInCategory() + 1);
Training training = new Training();
training.setUser(user);
try {
WorkingMemory workingMemory = trainingRules.newStatefulSession();
workingMemory.insert(user);
workingMemory.insert(training);
workingMemory.insert(user.getCategory());
workingMemory.fireAllRules();
} catch (Exception e) {
// TODO: logger
e.printStackTrace();
}
return training;
}
but i get
java.lang.NullPointerException
java.io.Reader.<init>(Unknown Source)
java.io.InputStreamReader.<init>(Unknown Source)
loadRules(ControllerDrools.java:48)
which is this line
Reader source = new InputStreamReader(ControllerDrools.class.getResourceAsStream(rulesPath));
Any body knows how to read this rules ? Where to put them ?
Thank you very much for reading this, it means a lot to me.
Using ControllerDrools.class.getResourceAsStream(rulesPath), your path should be relative from your ControllerDrools class package.
To make your path absolute, you should add a leading slash "/rules/ZatraziTrening.drl"
You can also use the following syntax to have absolute path :
this.getClass().getClassLoader().getResourceAsStream(rulesPath)
If you use maven, i advise you to put drl files directly in "src/main/resources"
I have a simple entity class and it is supposed to include unique names on it.
#Entity
class Package {
#PrimaryKey(sequence = "ID")
public Long id;
#SecondaryKey(relate = Relationship.ONE_TO_ONE)
public String name;
private Package() {}
public Package(String name) { this.name = name; }
#Override
public String toString() { return id + " : " + name; }
}
I want to use deferred writing option because of extensive modification. Here is the test i tried and its output.
final String dbfilename = "test01";
new File(dbfilename).mkdirs();
EnvironmentConfig config = new EnvironmentConfig().setAllowCreate(true);
Environment environment = new Environment(new File(dbfilename), config);
StoreConfig storeConfig = new StoreConfig().setAllowCreate(true).setDeferredWrite(true);
EntityStore store = new EntityStore(environment, "", storeConfig);
PrimaryIndex<Long, Package> primaryIndex = store.getPrimaryIndex(Long.class, Package.class);
try {
primaryIndex.put(new Package("package01")); // will be put.
primaryIndex.put(new Package("package01")); // throws exception.
} catch (UniqueConstraintException ex) {
System.out.println(ex.getMessage());
}
store.sync(); // flush them all
// expecting to find one element
SortedMap<Long,Package> sortedMap = primaryIndex.sortedMap();
for (Package entity : sortedMap.values()) {
System.out.println(entity);
}
Output
(JE 5.0.73) Unique secondary key is already present
1 : package01
2 : package01
So my question is that even if it throws exception while putting second package, why does it lists two packages. Any way to avoid this without using transactions?
Thanks.
I have an app where I filter messages according to some rules(existing some keywords or regexps). These rules are to be stored in .properties file(as they must be persistent). I've figured out how to read data from this file. here is the part of the code:
public class Config {
private static final Config ourInstance = new Config();
private static final CompositeConfiguration prop = new CompositeConfiguration();
public static Config getInstance() {
return ourInstance;
}
public Config(){
}
public synchronized void load() {
try {
prop.addConfiguration(new SystemConfiguration());
System.out.println("Loading /rules.properties");
final PropertiesConfiguration p = new PropertiesConfiguration();
p.setPath("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
p.load();
prop.addConfiguration(p);
} catch (ConfigurationException e) {
e.printStackTrace();
}
final int processors = prop.getInt("server.processors", 1);
// If you don't see this line - likely config name is wrong
System.out.println("Using processors:" + processors);
}
public void setKeyword(String customerId, String keyword){
}
public void setRegexp(String customerId, String regexp)
{}
}
as you see I'm going to add values to some properties. Here is the .properties file itself:
users = admin, root, guest
users.admin.keywords = admin
users.admin.regexps = test-5, test-7
users.root.keywords = root
users.root.regexps = *
users.guest.keywords = guest
users.guest.regexps =
I have a GUI for user to add keywords and regexps to this config. so, how to implement methods setKeyword and setRegexp?
The easyest way I found is to read the current values of the property to the String[], add there a new value and set property.
props.setProperty(fieldName, values);