Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,359
Community Members
 
Community Events
184
Community Groups

Is it possible to use build in function in Active Objects?

I'm developing plugin for Jira Server.
I need to run the simple query

"select ENTITY_ID, (START_TIME > 0) as STARTED from MyEntity order by STARTED". 

Is it possible to do it with atlassian active objects?

@Preload
public interface MyEntity extends Entity {

String getEntityId();
void setEntityId(String entityId);

@NotNull
long getStartTime();
void setStartTime(long startTime);
}

 

2 answers

I fixed the issue by myself. May be the solution would be helpful for somebody else.

I implemented own Query which removes "(START_TIME > 0) as STARTED" from canonical fields. It resolves the issue.

 

class MyQuery extends Query {

private static final long serialVersionUID = 1231231231231231231L;

public MyQuery(QueryType type, String fields) {
super(type, fields);
}

@Override
public String[] getCanonicalFields(EntityInfo<?, ?> entityInfo) {
String[] res = super.getCanonicalFields(entityInfo);
List<String> collect = Arrays.stream(res)
.filter(field -> !field.contains(">")) // this removes "(START_TIME > 0) as STARTED
.collect(Collectors.toList());
return collect.toArray(new String[]{});
}
}

Finally it didn't work for postgreSQL.

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 16, 2022

Hi @Irina S , yes it is possible. Active Objects uses net.java.ao.Query to prepare the query which can be used to search the data you need:

https://developer.atlassian.com/server/framework/atlassian-sdk/finding-entities/

@Martin Bayer _MoroSystems_ s_r_o__  - unfortunately it doesn't work.

 

Column STARTED doesn't exists in the db table.
'STARTED' is an alias. "(START_TIME > 0) as STARTED".
I need to order by the alias.


So the code silently returns nothing.

class MyEntityDao {
...
List<MyEntity> getItems() {
List
<MyEntity> entities = new ArrayList<>();
try {
Query query = Query.select("select ENTITY_ID, (START_TIME > 0) as STARTED")
.order("STARTED DESC")
.limit(5);
entityManager.stream(MyEntity.class, query, entities::add);
} catch (Exception ignored) {
}

return entities;
}
}

 

@RunWith(ActiveObjectsJUnitRunner.class)
@Jdbc(Hsql.class)
public class MyEntityDaoTest {

@Test
public void someTest() {
// add several items to the dao.
List<MyEntity> res = dao.getItems();
assertEquals(3, res); //falls because res is empty. It doesn't fell if query = Query.select("select ENTITY_ID") above;
}

}

It doesn't fell if query = Query.select("select ENTITY_ID") above.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events