ignore the resource which has been shared when share to public
@@ -13,6 +13,10 @@ import org.zstack.core.cloudbus.EventFacade;
import org.zstack.core.cloudbus.MessageSafe;
import org.zstack.core.componentloader.PluginRegistry;
import org.zstack.core.db.*;
+import org.zstack.core.db.DatabaseFacade;
+import org.zstack.core.db.Q;
+import org.zstack.core.db.SQLBatch;
+import org.zstack.core.db.SimpleQuery;
import org.zstack.core.db.SimpleQuery.Op;
import org.zstack.core.errorcode.ErrorFacade;
import org.zstack.core.workflow.FlowChainBuilder;
@@ -460,15 +464,24 @@ public class AccountBase extends AbstractAccount {
}
}
- List<SharedResourceVO> vos = new ArrayList<SharedResourceVO>();
+ new SQLBatch(){
+ @Override
+ protected void scripts() {
if (msg.isToPublic()) {
for (String ruuid : msg.getResourceUuids()) {
+ if(Q.New(SharedResourceVO.class)
+ .eq(SharedResourceVO_.ownerAccountUuid, msg.getAccountUuid())
+ .eq(SharedResourceVO_.resourceUuid, ruuid)
+ .eq(SharedResourceVO_.toPublic, msg.isToPublic())
+ .isExists()){
+ continue;
+ }
SharedResourceVO svo = new SharedResourceVO();
svo.setOwnerAccountUuid(msg.getAccountUuid());
svo.setResourceType(uuidType.get(ruuid));
svo.setResourceUuid(ruuid);
svo.setToPublic(true);
- vos.add(svo);
+ dbf.getEntityManager().persist(svo);
}
} else {
for (String ruuid : msg.getResourceUuids()) {
@@ -478,12 +491,12 @@ public class AccountBase extends AbstractAccount {
svo.setResourceType(uuidType.get(ruuid));
svo.setResourceUuid(ruuid);
svo.setReceiverAccountUuid(auuid);
- vos.add(svo);
+ dbf.getEntityManager().persist(svo);
}
}
}
-
- dbf.persistCollection(vos);
+ }
+ }.execute();
APIShareResourceEvent evt = new APIShareResourceEvent(msg.getId());
bus.publish(evt);
