Fórum

Service Builder get applications

Peter Hellstrand, modificado 12 Anos atrás.

Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
Hi
I am trying to use the service builder. This build does not succed


[javac] 	Collection applications)
[javac] Collection cannot be resolved to a type


but I hope you understand what I am trying to do. I would like to have class Function to have a collection of Application objects. I would like to do this.


List<application> applications = function.getApplications();
function.addApplication(application);  // I gues this one I have to create by my self in FunctionLocalServiceImpl
 </application>




        <entity name="Application" local-service="true" remote-service="false">
		<column name="applicationId" type="long" primary="true" />
		<column name="name" type="String" />
		<finder name="Id" return-type="Application">
			<finder-column name="applicationId" />
		</finder>
	</entity>

	<entity name="Function" local-service="true" remote-service="false">
		<column name="functionId" type="long" primary="true" />
		<column name="name" type="String" />
		<column name="applications" type="Collection" entity="Application" mapping-key="applicationId" /> 
		<finder name="Id" return-type="Function">
			<finder-column name="functionId" />
		</finder>
		<finder name="Applications" return-type="Collection">
			<finder-column name="applications" />
		</finder>	
	</entity>




So, to summarize, how do you work with collections in service builder?

Thanks
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
There is already finders by primary key. Entities should be defined as:


     <entity name="Application" local-service="true" remote-service="false">
        <column name="applicationId" type="long" primary="true" />
        <column name="name" type="String" />
    </entity>

    <entity name="Function" local-service="true" remote-service="false">
        <column name="functionId" type="long" primary="true" />
        <column name="name" type="String" />
        <column name="applications" type="Collection" entity="Application" mapping-key="applicationId" /> 
    </entity>


The persistence layer already has a method to get all entities, you just need to expose it in ApplicationLocalServiceImpl:


public List<application> getAllApplications() throws Exception {
  return applicationPersistence.findAll();
}
</application>


Adding a new application is done via the following code:


Application app = ApplicationLocalServiceUtil.createApplication(0);
...
ApplicationLocalServiceUtil.addApplication(app);
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
OK i found this in FunctionPersistence

 
public List<no.appo.services.model.application> getApplications( long pk) throws SystemException {
	return getApplications(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
}
</no.appo.services.model.application>


but still no way to add a Application to a function
thumbnail
Hitoshi Ozawa, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Service builder doesn't generate method to add methods. You'll have t o add it yourself in the Impl method. Just add a method to add a single Application and a method to add a List of Applcations which iterates through to call the single add method.
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
How do you suggest implementing the addAppliction?


public class FunctionImpl extends FunctionBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this class directly. All methods that expect a function model instance should use the {@link no.capraconsulting.appo.services.model.Function} interface instead.
	 */
	public FunctionImpl() {
	}
	
	public void addApplication(Application application){
		
	}
	
}

thumbnail
Hitoshi Ozawa, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
public class FunctionLocalServiceImpl extends FunctionLocalServiceBaseImpl {
public Application addApplication(int id,....){
....
}

public Application addApplication(List application){
// just iterate through calling addApplication(int id)
}
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
Thank you

But my concern is the connection between Applications and Functions.
Is application.setFunction(functionId) what needs to be done?
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
I tried this

this.functionPersistence.getApplications(function.getFunctionId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS).add(application);


but that list was read only.
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
To add an application, you'd call (in order):

Application app = ApplicationLocalServiceUtil.createApplication(primary key);
ApplicationLocalServiceUtil.addApplication(app);

To add the application to the function (which seems kinda backwards to me, btw):

Function func = FunctionLocalServiceUtil.getFunction(funcPrimKey);
func.getApplications().add(app);
FunctionLocalServiceUtil.updateFunction(func);
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
Thank you
This is the line i have been looking for.
func.getApplications().add(app);

My problem is that my function does not have a getApplications() or similar method.
That is what I don't understand.



	
	<entity name="Function" local-service="true" remote-service="false">
		<column name="functionId" type="long" primary="true" />
		<column name="name" type="String" />
		<column name="functionalAreaId" type="long" />
		<column name="applications" type="Collection" entity="Application" mapping-key="applicationId" /> 
		<finder name="Id" return-type="Function">
			<finder-column name="functionId" />
		</finder>
		<finder name="FunctionalArea" return-type="Collection">
			<finder-column name="functionalAreaId" />
		</finder>
	</entity>
	

thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
I think you should have a method like that since it is defined as part of the entity...

And you should still get rid of the Id finder since it duplicates the primary key method...
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
There is no such method but I agree with you that i should be. All other columns have get methods except from this one
 <column name="applications" type="Collection" entity="Application" mapping-key="applicationId" /> 





The extra finder is a result from this thread. (data base chaching)
http://www.liferay.com/community/forums/-/message_boards/message/12838482


Edit: Found this in the documentation so i guess you are right. I cant find any difference from my column though

For example:
<column
name="shoppingItemPrices"
type="Collection"
entity="ShoppingItemPrice"
mapping-key="itemId"
/>

The above column specifies that there will be a getter called
pojo.getShoppingItemPrices() that will return a collection. It will map to a
column called itemId in the table that maps to the entity ShoppingItemPrice.

If the entity and mapping-table attributes are specified and mapping-key is not,
then the Service Builder will assume you are specifying a many to many
relationship.
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
I used reflections to find all methods on my Function interface. I also created a new project and called it whit a copy paste of David H Nebinger entities from the post above. Same result.



Name: persist
Name: equals
Name: toString
Name: hashCode
Name: clone
Name: compareTo
Name: compareTo
Name: getName
Name: setName
Name: getPrimaryKey
Name: getExpandoBridge
Name: setPrimaryKey
Name: getPrimaryKeyObj
Name: setPrimaryKeyObj
Name: setExpandoBridgeAttributes
Name: toCacheModel
Name: toEscapedModel
Name: toEscapedModel
Name: toXmlString
Name: resetOriginalValues
Name: getModelClass
Name: getModelClassName
Name: getColumnBitmask
Name: getFunctionId
Name: getOriginalFunctionalAreaId
Name: getFunctionalAreaId
Name: getOriginalFunctionId
Name: setFunctionId
Name: setFunctionalAreaId
Name: isNew
Name: setNew
Name: isCachedModel
Name: setCachedModel
Name: isEscapedModel
Name: wait
Name: wait
Name: wait
Name: getClass
Name: notify
Name: notifyAll



Can I have a working service.xml from any of you that is actually working so I can compare with my?

Edit. I actually downloaded service.xml from "Liferay in action" source code. That code does no generate getter methods for the collections ether.
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
More people with the same issue

http://www.liferay.com/community/forums/-/message_boards/message/11747895
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
Is it fair to report a bug on this one? Could someone else be kind and try to run any service.xml in a new project just to see if getters and setters are generated for the collections.
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: Service Builder get applications

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Well, the answer is actually to review the service builder code... I'm going through the 6.0 EE SP2 source, but I'm guessing it's going to be the same for the CE lines...

When SB is parsing an entity, it distinguishes between a regular column and a collection column. Collection columns are tracked separately.

The com.liferay.portal.tools.servicebuilder.dependencies.model.ftl (the template used to generate the model interface) only creates getters/setters for regular columns, not any of the collection columns.

The weird thing is that I cannot find any reference to the collectionList member of com.liferay.portal.tools.servicebuilder.Entity outside of the initial population.

Since the model.ftl only works off of the regular columns of the Entity class, the collections will always be excluded from the model, as well as all of the other classes.

Doing a global search of the portal source, it would appear that the collectionList member is not referenced anywhere, and this is most likely a bug.
Peter Hellstrand, modificado 12 Anos atrás.

RE: Service Builder get applications

Regular Member Postagens: 166 Data de Entrada: 30/11/11 Postagens Recentes
Thank you very much for your efforts. This one was driving me crazy. emoticon
Is there any work around to work with a collection? Do I have to go download a older SDK or wait?

Edit: I have reported it
http://issues.liferay.com/browse/LPS-26147